From patchwork Fri Nov 15 15:30:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13876447 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 63B02D68BC8 for ; Fri, 15 Nov 2024 15:31:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 601926B009B; Fri, 15 Nov 2024 10:31:43 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 5B11E6B009C; Fri, 15 Nov 2024 10:31:43 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4049C6B009D; Fri, 15 Nov 2024 10:31:43 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 1CF216B009B for ; Fri, 15 Nov 2024 10:31:43 -0500 (EST) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id C7A921418F0 for ; Fri, 15 Nov 2024 15:31:42 +0000 (UTC) X-FDA: 82788717816.10.4238A4F Received: from mail-yw1-f180.google.com (mail-yw1-f180.google.com [209.85.128.180]) by imf16.hostedemail.com (Postfix) with ESMTP id B03D5180024 for ; Fri, 15 Nov 2024 15:30:55 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=toxicpanda-com.20230601.gappssmtp.com header.s=20230601 header.b=B8OiZm4g; dmarc=none; spf=none (imf16.hostedemail.com: domain of josef@toxicpanda.com has no SPF policy when checking 209.85.128.180) smtp.mailfrom=josef@toxicpanda.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1731684636; a=rsa-sha256; cv=none; b=wvgU7nbGEd+o61BHLUtD/gNzs0tGxXZZHrF/d2xRIOyxX8gKdL+pz42WNtht+zLnoV4yys lvh8HNheJABkPZDCDoxDeZ7M2u+g7PfC3zwHbCKJZPhwsa49WlBHqvREfrrify6yHtkSKe gKbhGOthEUEfRaFfG2od+9Jzo8EcwmQ= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=toxicpanda-com.20230601.gappssmtp.com header.s=20230601 header.b=B8OiZm4g; dmarc=none; spf=none (imf16.hostedemail.com: domain of josef@toxicpanda.com has no SPF policy when checking 209.85.128.180) smtp.mailfrom=josef@toxicpanda.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1731684636; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=28nbpQbjD2HwWvaUP2yIn55iQ73mbNzvgMCNeqvC6/0=; b=uVrZmUNA9ujnnmN53MkWXPitHza9ivcKJzauHCzRP/V5vneNx+4o9QO63DyCgw/uOdYG2P HGJTF4KkHl7ThQsrv1dr2+fSF8+8PrUJnFPIojKkQM37wJgvq2SyeYGD8cWzDWjbAa3Dkm Mr1jmihfVXpyQq0epkD8zVSBNoIpPMY= Received: by mail-yw1-f180.google.com with SMTP id 00721157ae682-6ea07d119b7so16596197b3.0 for ; Fri, 15 Nov 2024 07:31:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1731684700; x=1732289500; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=28nbpQbjD2HwWvaUP2yIn55iQ73mbNzvgMCNeqvC6/0=; b=B8OiZm4gNFiXzs8IUwsntLL3p+2OLBSgdwuGHhDYfiEHCuTJdA+2iS0DjUGmKYgJ11 ogdnft2c0V83Dg9hBXbwcu+hambhu8VOARBMR7yD0DSwJnGG/mfkSoovdpa0bqT/dgI+ tHcpuOmhyIeEqiBlq4rz78WtVNZ1hVB4+7/Clfv1H4LoKf3GyH+8zVRbSMZu0YgBkje5 ckeTOEqycWGK4/ZVo/kexyXiMK74LK4HdiBs7+mgqUqJeeAx/uVL/lt7+rximuznDFYG 7fe6qCiOpWzy/KuBrymehqpCjI15Gcwgkr8a3VS2I1k9WQqsXUm+K3cRH1i3NRWoCjff 6zkA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731684700; x=1732289500; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=28nbpQbjD2HwWvaUP2yIn55iQ73mbNzvgMCNeqvC6/0=; b=CsyYj/mo4r6yHbZxhpfI56JnOpkVIsmKORmLXDrP0+1yLLOVq6MNmyH3GsUDfTmj0P M+6u0Qx3J4QOqtIikhAIe0pUhoeBtKrkR3EzI51Aq3RHcvmvKr3l4sVOzENSrqLrLoIa aZtBUM1kflk7A13SU6aEPZJwYhst+tsIG4kpSXs3dZJ0cLtXFC9j+yS08iaVYaBh2Dfk zPeI7CRuSGMA0zmtQEe1GaBdvxiatkFMGVDdxBC3MefP2orkNSdYFhZ8zMnXiRXrrtdo F1+tn8GyGEvDFGzV+LOF2kQb3ev2GegcOhBGoeGi2G+0hEpq8j6EmWOGhhBjru8XIKlA mFyQ== X-Forwarded-Encrypted: i=1; AJvYcCWizdsWFsrASVj+ID0iFQuJoJneQ+O3KdrCxKBEenMhfyymQ4OTZ78W32MCprGokYKaOt9et5+/3A==@kvack.org X-Gm-Message-State: AOJu0YzOVXsR2op5wseJae/zsl0qU/8xyddXaeaL3usPPCQkvwSo00di 8EVduA9kU2f0f9UL/JnwHGjymtAzvxwhdcZ2z0jHF73Mga3CrlO0wQT4o0iaBSo= X-Google-Smtp-Source: AGHT+IEjW291jTkKzHI4Ae+C3bnCRuhWYH/1lq2dSUG1bbeWzCUoX3SJFcI3pBBBVFezHIznGLjunA== X-Received: by 2002:a05:690c:67c9:b0:6ee:4bee:d912 with SMTP id 00721157ae682-6ee55c304afmr35158487b3.21.1731684699892; Fri, 15 Nov 2024 07:31:39 -0800 (PST) Received: from localhost (syn-076-182-020-124.res.spectrum.com. [76.182.20.124]) by smtp.gmail.com with ESMTPSA id 00721157ae682-6ee44413323sm7692477b3.77.2024.11.15.07.31.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Nov 2024 07:31:39 -0800 (PST) From: Josef Bacik To: kernel-team@fb.com, linux-fsdevel@vger.kernel.org, jack@suse.cz, amir73il@gmail.com, brauner@kernel.org, torvalds@linux-foundation.org, viro@zeniv.linux.org.uk, linux-xfs@vger.kernel.org, linux-btrfs@vger.kernel.org, linux-mm@kvack.org, linux-ext4@vger.kernel.org Subject: [PATCH v8 11/19] fanotify: report file range info with pre-content events Date: Fri, 15 Nov 2024 10:30:24 -0500 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Queue-Id: B03D5180024 X-Rspamd-Server: rspam11 X-Stat-Signature: yoiayi13zopeer1inym8x6o8zhu1ydec X-HE-Tag: 1731684655-897145 X-HE-Meta: U2FsdGVkX1/ydsVgDMVrxL+NmB/8JZhxFLq9dU+k0dQl8Bl2TRgc6Oey6dSbmWe6kT8HgF8iyolIdLNMZvusaX0d3JD32RH/A61UQraQkD+X/VsLJwXLVwK6osnEV8r18/J0mMxj4P4v3fgM4AMgAmVTGJtW/vWsAEO9fY1H69A8cwVmgmFG88oY1EaBblNZA0KfTlEBSDkaPhTxmOAlGojUHwX5UVQowWif9Odt8UBgq+cv0L7RUyVfbketmKo6hUC4O/n+aMzJuq8feCzX4Ip6kOugFU4YLsMGZv27tm1V+NdzAq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G5J2W6jkt9BpBE7EfSlSEbCJWShZYMdTvMc4GLwtQ7hXknj12z3U1x9NeTZhJcn8QquU= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000025, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Amir Goldstein With group class FAN_CLASS_PRE_CONTENT, report offset and length info along with FAN_PRE_ACCESS pre-content events. This information is meant to be used by hierarchical storage managers that want to fill partial content of files on first access to range. Signed-off-by: Amir Goldstein --- fs/notify/fanotify/fanotify.h | 8 +++++++ fs/notify/fanotify/fanotify_user.c | 38 ++++++++++++++++++++++++++++++ include/uapi/linux/fanotify.h | 8 +++++++ 3 files changed, 54 insertions(+) diff --git a/fs/notify/fanotify/fanotify.h b/fs/notify/fanotify/fanotify.h index 93598b7d5952..7f06355afa1f 100644 --- a/fs/notify/fanotify/fanotify.h +++ b/fs/notify/fanotify/fanotify.h @@ -448,6 +448,14 @@ static inline bool fanotify_is_perm_event(u32 mask) mask & FANOTIFY_PERM_EVENTS; } +static inline bool fanotify_event_has_access_range(struct fanotify_event *event) +{ + if (!(event->mask & FANOTIFY_PRE_CONTENT_EVENTS)) + return false; + + return FANOTIFY_PERM(event)->ppos; +} + static inline struct fanotify_event *FANOTIFY_E(struct fsnotify_event *fse) { return container_of(fse, struct fanotify_event, fse); diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c index 5ea447e9e5a8..c7938d9e8101 100644 --- a/fs/notify/fanotify/fanotify_user.c +++ b/fs/notify/fanotify/fanotify_user.c @@ -121,6 +121,8 @@ struct kmem_cache *fanotify_perm_event_cachep __ro_after_init; sizeof(struct fanotify_event_info_pidfd) #define FANOTIFY_ERROR_INFO_LEN \ (sizeof(struct fanotify_event_info_error)) +#define FANOTIFY_RANGE_INFO_LEN \ + (sizeof(struct fanotify_event_info_range)) static int fanotify_fid_info_len(int fh_len, int name_len) { @@ -180,6 +182,9 @@ static size_t fanotify_event_len(unsigned int info_mode, if (info_mode & FAN_REPORT_PIDFD) event_len += FANOTIFY_PIDFD_INFO_LEN; + if (fanotify_event_has_access_range(event)) + event_len += FANOTIFY_RANGE_INFO_LEN; + return event_len; } @@ -516,6 +521,30 @@ static int copy_pidfd_info_to_user(int pidfd, return info_len; } +static size_t copy_range_info_to_user(struct fanotify_event *event, + char __user *buf, int count) +{ + struct fanotify_perm_event *pevent = FANOTIFY_PERM(event); + struct fanotify_event_info_range info = { }; + size_t info_len = FANOTIFY_RANGE_INFO_LEN; + + if (WARN_ON_ONCE(info_len > count)) + return -EFAULT; + + if (WARN_ON_ONCE(!pevent->ppos)) + return -EINVAL; + + info.hdr.info_type = FAN_EVENT_INFO_TYPE_RANGE; + info.hdr.len = info_len; + info.offset = *(pevent->ppos); + info.count = pevent->count; + + if (copy_to_user(buf, &info, info_len)) + return -EFAULT; + + return info_len; +} + static int copy_info_records_to_user(struct fanotify_event *event, struct fanotify_info *info, unsigned int info_mode, int pidfd, @@ -637,6 +666,15 @@ static int copy_info_records_to_user(struct fanotify_event *event, total_bytes += ret; } + if (fanotify_event_has_access_range(event)) { + ret = copy_range_info_to_user(event, buf, count); + if (ret < 0) + return ret; + buf += ret; + count -= ret; + total_bytes += ret; + } + return total_bytes; } diff --git a/include/uapi/linux/fanotify.h b/include/uapi/linux/fanotify.h index 7596168c80eb..0636a9c85dd0 100644 --- a/include/uapi/linux/fanotify.h +++ b/include/uapi/linux/fanotify.h @@ -146,6 +146,7 @@ struct fanotify_event_metadata { #define FAN_EVENT_INFO_TYPE_DFID 3 #define FAN_EVENT_INFO_TYPE_PIDFD 4 #define FAN_EVENT_INFO_TYPE_ERROR 5 +#define FAN_EVENT_INFO_TYPE_RANGE 6 /* Special info types for FAN_RENAME */ #define FAN_EVENT_INFO_TYPE_OLD_DFID_NAME 10 @@ -192,6 +193,13 @@ struct fanotify_event_info_error { __u32 error_count; }; +struct fanotify_event_info_range { + struct fanotify_event_info_header hdr; + __u32 pad; + __u64 offset; + __u64 count; +}; + /* * User space may need to record additional information about its decision. * The extra information type records what kind of information is included.