From patchwork Mon Nov 11 20:17:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13871227 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 26BD1D3ABF4 for ; Mon, 11 Nov 2024 20:19:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 81BC18D0006; Mon, 11 Nov 2024 15:19:27 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 7CC9E8D0001; Mon, 11 Nov 2024 15:19:27 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5F7838D0006; Mon, 11 Nov 2024 15:19:27 -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 402568D0001 for ; Mon, 11 Nov 2024 15:19:27 -0500 (EST) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id F3A45C1042 for ; Mon, 11 Nov 2024 20:19:26 +0000 (UTC) X-FDA: 82774928754.29.D4D6A02 Received: from mail-qk1-f180.google.com (mail-qk1-f180.google.com [209.85.222.180]) by imf07.hostedemail.com (Postfix) with ESMTP id B737B4001E for ; Mon, 11 Nov 2024 20:18:27 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=toxicpanda-com.20230601.gappssmtp.com header.s=20230601 header.b=X0i4XsQ+; spf=none (imf07.hostedemail.com: domain of josef@toxicpanda.com has no SPF policy when checking 209.85.222.180) 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=1731356192; 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=LGryhZjhYAebksFaS9pdbr55rRjOBk5banX6k6b7VeY=; b=ibPFGbPOeMzd8D7Dy6+mqZZpdeNiV4RL5uXnxgQeu/l3Q/wGJAMHzEwZpD2KLK8UWI6Gv/ k8UhD36WJ5x0qyiyJ4P9LKO5kgyJWb7ScRW//sI2YU0LTHaMS7Vfu5ji0iENk9p9jednY3 l/WauXBACEJnxpzDOpwFgIaRbOj8+VY= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=toxicpanda-com.20230601.gappssmtp.com header.s=20230601 header.b=X0i4XsQ+; spf=none (imf07.hostedemail.com: domain of josef@toxicpanda.com has no SPF policy when checking 209.85.222.180) smtp.mailfrom=josef@toxicpanda.com; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1731356192; a=rsa-sha256; cv=none; b=Or+Voi4jmseUUCbXlk55v6hK8PxjKDpcjCYRt84jyZ1uNbiTrGIeISqYJpyCF8bJkqHX45 LV158EG3eiJJBZVGdekh2SHyKVamPbXB/e1aIJyXV8C7sYREmNnYNlRPWBXd7Oh+VC6rnA CiPK8XShZPTkXO4ZNAoU5jDQNXEXUUA= Received: by mail-qk1-f180.google.com with SMTP id af79cd13be357-7b13fe8f4d0so308243885a.0 for ; Mon, 11 Nov 2024 12:19:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1731356364; x=1731961164; 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=LGryhZjhYAebksFaS9pdbr55rRjOBk5banX6k6b7VeY=; b=X0i4XsQ+R/oOi/GbBqRW1muw+qY5NX3bixcLgtUl9UPiKop5l0oPUyF8jIRdyTz2zY M7AgNCXw2Yy+i66tNyKJZ0ZRdeZ4CXh6jjlFUD5PMrykiRqvIoUuvAXNVkxUMf8IEiu0 WCcTLhvfwXQhq30lNLWw5qsWrhJCcVfrKT3Y5AmXcqDmelrXa1Y9CwRix2LREnNhGAKY Whk2Am7PeimIUeGghCrD6ePisT5BTNroBkPvnOlpVEObjJfU0YPKDT3IaXyOHqpa3zuD Wqnhgcj5m60vQJ+kZeyZgieg1tE+hkW60/g4fvtk+32Yu29w3pknqJ+hW26ut7NDflwH pfDQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731356364; x=1731961164; 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=LGryhZjhYAebksFaS9pdbr55rRjOBk5banX6k6b7VeY=; b=RsNEAgO50oQqnjGlZXHQ1QTQ3pZ3tBiBAjwNJJm3G9FusTly1/WvQ82/7Ig2ymCnAu /5Pu9MXrRuSFxQgdd8xl8TJ8unWF/Zy/r0EmIOs4ZDmXhmI5RzM5a2uNQdg9J33SQUfm FAVirvBuUWkFrMlSp2MIZKiZoPLjnV1f+9B2k97ZZKsWsfstvI68ndt1nXHU4GO3vXKI X+/PqCezDYCBszOMhw1iiybaR/HsL8DDYGRhEiBiRlEbYdoEO4y381X7L8Ht+cIqT1t0 TOnkvI6U+AlwXtFq+bRGawABEnRSUHz+mYu85hdDVAurvP0IMadjghtl7JSb8LiHnd32 dK3Q== X-Forwarded-Encrypted: i=1; AJvYcCUdgdA5TgxYr+tmjGsLAV3w2eG0FN9uZXwPhKIvJnPE+pVg7m94/Ed9z4D98TiZ6FIn1pVZV4ahUA==@kvack.org X-Gm-Message-State: AOJu0Yz+wwCrjyQmrwbjHh/SDEQdbH3Bd1/7n28d7T5USSEFFwb6d+Os SsL/onaMLN4G0Qau5NgoGjX1Zt/tBZ4PKps971grn425a60YGoNDZ1AInhDRW25uByWOcTOmiwX a X-Google-Smtp-Source: AGHT+IF22B/D1c9DuKVBsfxqpgJ2vY2z65TspT6Q0Pw0A6vpDeL8FShi0pjnRxFhWA3rscCdafTgdQ== X-Received: by 2002:a05:620a:1a94:b0:7b1:48ff:6b3c with SMTP id af79cd13be357-7b331d8b905mr1736558085a.16.1731356364156; Mon, 11 Nov 2024 12:19:24 -0800 (PST) Received: from localhost (syn-076-182-020-124.res.spectrum.com. [76.182.20.124]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7b32ac57002sm525823885a.43.2024.11.11.12.19.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Nov 2024 12:19:23 -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 v6 09/17] fanotify: report file range info with pre-content events Date: Mon, 11 Nov 2024 15:17:58 -0500 Message-ID: <2146833d30122ef9a031e231d8ced7d8a085196d.1731355931.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: B737B4001E X-Stat-Signature: g1swt5fie99szfwpmwqex4nkjyukrp9z X-Rspam-User: X-HE-Tag: 1731356307-966751 X-HE-Meta: U2FsdGVkX1+dzpaiO4BK0qI6wty3GMDyVWheLVJLUCqhqqpqkzQfyLVfz6VytI0kJDuarntVwz3C4CDWR7Oip6OjPfETHfTyk/isOOkz6aNslBxzTMFXAzeypAjSlK5dCO+LPop1JPZh3uQYB+YVfLMou4DlRV4J6nIg6Ex3rijuJyDP06Ig6vjaFJn9ZotgRUSb5pZgsd1nmmvuRsvpcii5TAHHlNPDVgv92Eil2xfm3HtlCKxx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KoG7hYdrfCw== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000002, 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 da9cf09565ce..17402f9e8609 100644 --- a/fs/notify/fanotify/fanotify_user.c +++ b/fs/notify/fanotify/fanotify_user.c @@ -123,6 +123,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) { @@ -182,6 +184,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; } @@ -519,6 +524,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, @@ -640,6 +669,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.