From patchwork Thu Nov 21 11:22:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kara X-Patchwork-Id: 13881879 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 DA317D6ED09 for ; Thu, 21 Nov 2024 11:23:00 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7A80F6B009A; Thu, 21 Nov 2024 06:22:32 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 709556B00A3; Thu, 21 Nov 2024 06:22:32 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0F2846B009E; Thu, 21 Nov 2024 06:22:31 -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 C16F46B009A for ; Thu, 21 Nov 2024 06:22:31 -0500 (EST) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 75EA4140A75 for ; Thu, 21 Nov 2024 11:22:31 +0000 (UTC) X-FDA: 82809861414.13.EC3A672 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) by imf23.hostedemail.com (Postfix) with ESMTP id A1F61140002 for ; Thu, 21 Nov 2024 11:21:54 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=RpTBYVHP; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=4cSGDcxj; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=RpTBYVHP; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=4cSGDcxj; spf=pass (imf23.hostedemail.com: domain of jack@suse.cz designates 195.135.223.130 as permitted sender) smtp.mailfrom=jack@suse.cz; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1732188087; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=V2VbJr1FOyyDrN/JRXZjBf5YYpp5FPhCnXLj0Nz6ko0=; b=Fadx3YWJlDoGAn9VgPT1U8+We6e2Yiv3fJFW5J0axV9wXS4HWM4rPttbWzW95N71pHRYVw GHwuBh18JL1x5ftEglZk4/8HKex+rDkjSyWSLkK6wLUPYXKdrHRlQEZUHJJPtrdlsE60I3 gFWCPR8lQ6bt7ZLjjqWg37MaElMFqhM= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1732188087; a=rsa-sha256; cv=none; b=428pEhosATepydtHcUC6oF3+/ihnlyttnC4rhnrju+VmZoAKZy/jiKZ9m5hKqKUKDEVxar zZSQ7KkVVLw8SpKgvIlK8LVPrK4WHswViwt3J96eFaT4UQy9ql/k6V+3OYCZ1HHC8KsVVB /+TBr1n2gdSSbmnTU1Go6BdQwwV+BgM= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=RpTBYVHP; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=4cSGDcxj; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=RpTBYVHP; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=4cSGDcxj; spf=pass (imf23.hostedemail.com: domain of jack@suse.cz designates 195.135.223.130 as permitted sender) smtp.mailfrom=jack@suse.cz; dmarc=none Received: from imap1.dmz-prg2.suse.org (unknown [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 948AA21A05; Thu, 21 Nov 2024 11:22:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1732188144; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=V2VbJr1FOyyDrN/JRXZjBf5YYpp5FPhCnXLj0Nz6ko0=; b=RpTBYVHPZnilU9S5C9NOEFhWpEVBSMnDFvTsJ4iFT0shPGf5eUNWrADAWVO+il9ON92iay g7Qcx71u73v3Q5U3cqjUDvi2qWHdoGNAhUy95Wnpd5J/db7Zr5xsqNURvagbxIcXYmWkZQ Lb9VGFXaRLCEWdEsMtE9aFMryGAw+hM= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1732188144; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=V2VbJr1FOyyDrN/JRXZjBf5YYpp5FPhCnXLj0Nz6ko0=; b=4cSGDcxj0ha4IdD6XNUM9muDeVH1TTEQMvC82P1Wr6XqZJ2NFN43qq1OeY3Vx7aFNlpGFs 9SHrL9s/1nDTAUDg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1732188144; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=V2VbJr1FOyyDrN/JRXZjBf5YYpp5FPhCnXLj0Nz6ko0=; b=RpTBYVHPZnilU9S5C9NOEFhWpEVBSMnDFvTsJ4iFT0shPGf5eUNWrADAWVO+il9ON92iay g7Qcx71u73v3Q5U3cqjUDvi2qWHdoGNAhUy95Wnpd5J/db7Zr5xsqNURvagbxIcXYmWkZQ Lb9VGFXaRLCEWdEsMtE9aFMryGAw+hM= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1732188144; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=V2VbJr1FOyyDrN/JRXZjBf5YYpp5FPhCnXLj0Nz6ko0=; b=4cSGDcxj0ha4IdD6XNUM9muDeVH1TTEQMvC82P1Wr6XqZJ2NFN43qq1OeY3Vx7aFNlpGFs 9SHrL9s/1nDTAUDg== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 89A6113927; Thu, 21 Nov 2024 11:22:24 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id bTaZIfAXP2c9fwAAD6G6ig (envelope-from ); Thu, 21 Nov 2024 11:22:24 +0000 Received: by quack3.suse.cz (Postfix, from userid 1000) id 329D6A08E0; Thu, 21 Nov 2024 12:22:24 +0100 (CET) From: Jan Kara To: Cc: Amir Goldstein , Josef Bacik , brauner@kernel.org, Linus Torvalds , Al Viro , linux-xfs@vger.kernel.org, linux-btrfs@vger.kernel.org, linux-ext4@vger.kernel.org, linux-mm@kvack.org, Jan Kara Subject: [PATCH 13/19] fanotify: disable readahead if we have pre-content watches Date: Thu, 21 Nov 2024 12:22:12 +0100 Message-Id: <20241121112218.8249-14-jack@suse.cz> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20241121112218.8249-1-jack@suse.cz> References: <20241121112218.8249-1-jack@suse.cz> MIME-Version: 1.0 X-Stat-Signature: ouhq5ozx1eoppm5arjb117apoqq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G2UyO5LPlg8Cm6eGIjI6y5ll7PK1jSBrnGUNhImXYWGPdrTWhvQdjpRhHVwmX1+24PPwXuPECJUxaihB6apSYoS7jO4wp9K60AV0xDkZp/bpAIwsZccltNjrBmHALGwS5TxnCEppysfYG9U7N5oq28zP7ExGe8dLZWpmGYBY/aSuGTZ/sZUAOdfaavo/pH/yzjnqGjPzwworqqKcT4dqYWPm6ds2RgRfpE9Lse7CprzLQCr70SF7wFA02VTUPVnL4SHDevF2Vy2wLm7/Opnpc5I/CXLsV4wd+xwKnUF0Zw4ilwghXUHH60L1EAnnJ1B7USCP+CPYad+Ecn/ZF4wV+V4i+bi2+Nrfyy56VwqxX43qRGhJSey93cKsrnAZFG5ST5dJ7NeFXuktiUc8lDw== 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: Josef Bacik 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 Signed-off-by: Jan Kara Link: https://patch.msgid.link/70a54e859f555e54bc7a47b32fe5aca92b085615.1731684329.git.josef@toxicpanda.com --- mm/filemap.c | 12 ++++++++++++ mm/readahead.c | 14 ++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/mm/filemap.c b/mm/filemap.c index 36d22968be9a..98f15dccff89 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -3149,6 +3149,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 (unlikely(FMODE_FSNOTIFY_HSM(file->f_mode))) + 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) { @@ -3217,6 +3225,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 (unlikely(FMODE_FSNOTIFY_HSM(file->f_mode))) + 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 3dc6c7a128dd..e482f9f2e159 100644 --- a/mm/readahead.c +++ b/mm/readahead.c @@ -128,6 +128,7 @@ #include #include #include +#include #include "internal.h" @@ -544,6 +545,15 @@ 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. Filesystems supporting HSM must make sure to not call + * this function with ractl->file unset for files handled by HSM. + */ + if (ractl->file && unlikely(FMODE_FSNOTIFY_HSM(ractl->file->f_mode))) + 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 +632,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 && unlikely(FMODE_FSNOTIFY_HSM(ractl->file->f_mode))) + return; + /* * Same bit is used for PG_readahead and PG_reclaim. */