From patchwork Wed Sep 4 20:27: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: 13791362 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 9CDBBCD4F24 for ; Wed, 4 Sep 2024 20:29:39 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 20F0B6B00E7; Wed, 4 Sep 2024 16:29:31 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 195A86B012F; Wed, 4 Sep 2024 16:29:31 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EDC646B0130; Wed, 4 Sep 2024 16:29:30 -0400 (EDT) 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 B85606B00E7 for ; Wed, 4 Sep 2024 16:29:30 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 7B3BD1C144B for ; Wed, 4 Sep 2024 20:29:30 +0000 (UTC) X-FDA: 82528196100.27.4C19F08 Received: from mail-qk1-f175.google.com (mail-qk1-f175.google.com [209.85.222.175]) by imf13.hostedemail.com (Postfix) with ESMTP id C15CD20004 for ; Wed, 4 Sep 2024 20:29:28 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=toxicpanda-com.20230601.gappssmtp.com header.s=20230601 header.b=F5EqOhem; dmarc=none; spf=none (imf13.hostedemail.com: domain of josef@toxicpanda.com has no SPF policy when checking 209.85.222.175) smtp.mailfrom=josef@toxicpanda.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1725481744; a=rsa-sha256; cv=none; b=ZTa6v05o+SyNZIqCsgs3FtWqrkJDsCLNtdzlSXDT4bmiXc1JOOukrjfT5XgdbDyTanljCQ HRLBvj0BQFw2AagwKPXFKktIfgSfgFKwQmohKqFC2DtLRnJzJgXzUKBlsQPTVBwQFv1sgU lRomVuyv7T9ENFwtBUXpD3VHYwemAAo= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=toxicpanda-com.20230601.gappssmtp.com header.s=20230601 header.b=F5EqOhem; dmarc=none; spf=none (imf13.hostedemail.com: domain of josef@toxicpanda.com has no SPF policy when checking 209.85.222.175) smtp.mailfrom=josef@toxicpanda.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1725481744; 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=kdFADlNMi9J5+Jo97YgtLX17z0QeGZLAaqk7oAQuL90=; b=kz64in/yDBpRwT34jT3f7AnjLYVyzCFDj5fv7Ugkzlc/OPcHcycsmgrIfEatre+ikN4YE6 WkSswQGyEPNnQY5D/pXtu4R7S41LNyacfId+GNmHZC72waXzXe0uGoUEN4WOAgkdfGOQrj ryoOf98pNIBVzb7iNJU3n2s+RAZjPYM= Received: by mail-qk1-f175.google.com with SMTP id af79cd13be357-7a7fd79ff71so1255185a.2 for ; Wed, 04 Sep 2024 13:29:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1725481768; x=1726086568; 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=kdFADlNMi9J5+Jo97YgtLX17z0QeGZLAaqk7oAQuL90=; b=F5EqOhemcLKRzY08N29q0CM51heYi3TEsUod5J5eYQ6n8tKxYXkII/kZE1RdMlIR4P jMJq6a8IcUGyQIh0uwSKytcL5Q1D+uvxKF0rtEfatYQhmiZ15jQVtcVX+E+G9URl6+io WZloDaZeZzdjY9+pQHH+quX1Uie1vVibx3D6PjcvkZdrgz7SDUWNUiul3ySohFxAYbwn CJJFyJUTWZLh8ObGCXuwEJFRsl6Kk7dbtVvYA3N2PVnHabmjKxSRxMGrjK2RsUwqQxWC XrrugdORYOBV++j5xMwr/yOOszZnaMmZyNeShEHiXPlID2P6Y5hstm9qYMpt4JQ2J7fh wgWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725481768; x=1726086568; 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=kdFADlNMi9J5+Jo97YgtLX17z0QeGZLAaqk7oAQuL90=; b=pFapZ6lPQ7+AiBz13974oQd/mGNjGzHDgqjaRfBBBphifSVXjrTCO2kdNNPIqJ7yn9 RLdl4uMEQ1aZ7itEtgA3mIVuHlADLA1ysmi6R/espqlI2Ex8QFqme92yXWN7pbGmyYQl Xe6ktr5m7Kmlba0xvtM81fVjCt85nx2hDxtPBjGsSyjvUMCmf/SsBYyxwG3Hm0pVNEAI 6Zw+fLVeQ8U12r8DY2XZVpKOHhaZdoUNXn5cvA/0+2wDXMW/dbxteOaj/YQq/rPIrVoK ATtEUqnawGfp/Cm3YkpirPueidbf904J2SvudFXnGkO0toxkrzA2ysC4H/6Ykd9GbL1x IdPw== X-Forwarded-Encrypted: i=1; AJvYcCVoBzpYsLlErq1lJBHDJl13QkfAhHHT0BleV3KoaZIdsLikM7649tU+h9k5Bz1oqGe4LcTC2X4glg==@kvack.org X-Gm-Message-State: AOJu0YxZNm8rM13UPFYKoIZE1BigfQ+2ruYcazgJxHsN1Fy9lzJboN5o zyBo1KJGzpmPCG6H2SuSd/z3UvSeRO2jNgeGJpkVnnnA7Ep6QBlDuIOhvjP6nuU= X-Google-Smtp-Source: AGHT+IGx6um9uXhEhda5h73KKWCoNW2FF/dwyP15+JSEZ33BwCH3HCg2dZ3AYVIuYxLr9QIEDkXCMg== X-Received: by 2002:a05:620a:1724:b0:79e:fc9c:4bcb with SMTP id af79cd13be357-7a8931ddae4mr1887788985a.11.1725481767911; Wed, 04 Sep 2024 13:29:27 -0700 (PDT) Received: from localhost (syn-076-182-020-124.res.spectrum.com. [76.182.20.124]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7a98ef4a2ebsm15638785a.67.2024.09.04.13.29.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Sep 2024 13:29:27 -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 08/18] fanotify: report file range info with pre-content events Date: Wed, 4 Sep 2024 16:27:58 -0400 Message-ID: <0833eaada39f0a33e655b47f2d15a5a37cf39a78.1725481503.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: C15CD20004 X-Rspamd-Server: rspam01 X-Stat-Signature: y8a51316bfjxqjrmm7r7wh886nwmjax6 X-HE-Tag: 1725481768-950325 X-HE-Meta: U2FsdGVkX1/1NN1AVD7DiAVn7/FrwsZ0SD/IS2WSaQ3ehp8FYc+whpf4gzVjAlWvsKodl0NX5StArS+gQgw14fgwkbN47Es/nZKFhhxDk4KdzFmLjASafDzV1o+Dktp263ZGXZhEVpOZf/p90m6WF2s6lINjKCoi/tAJN7dVm28UwiS44JR/e7JMKoqA1IAbakWU3KI6h1DOM0GTSL04keD8aTRR5eFMy3WE1L0ERQr7wjdIK2zam+NZUh7CcYTlh4I2wUtj87Ymeow0o+n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=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 and FAN_PRE_MODIFY permission 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 5ece186d5c50..ed56fe6f5ec7 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; } @@ -526,6 +531,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, @@ -647,6 +676,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 ac00fad66416..6136e8a9f9f3 100644 --- a/include/uapi/linux/fanotify.h +++ b/include/uapi/linux/fanotify.h @@ -145,6 +145,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 @@ -191,6 +192,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.