From patchwork Mon Nov 11 20:18:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13871230 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 B1E44D3ABF4 for ; Mon, 11 Nov 2024 20:19:40 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6BD966B008A; Mon, 11 Nov 2024 15:19:32 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 66F906B008C; Mon, 11 Nov 2024 15:19:32 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 471656B00A3; Mon, 11 Nov 2024 15:19:32 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 271AA6B008A for ; Mon, 11 Nov 2024 15:19:32 -0500 (EST) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id D3BAAADDDC for ; Mon, 11 Nov 2024 20:19:31 +0000 (UTC) X-FDA: 82774928124.23.2A70023 Received: from mail-qk1-f182.google.com (mail-qk1-f182.google.com [209.85.222.182]) by imf08.hostedemail.com (Postfix) with ESMTP id D7F55160006 for ; Mon, 11 Nov 2024 20:19:02 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=toxicpanda-com.20230601.gappssmtp.com header.s=20230601 header.b=DiPyz97R; spf=none (imf08.hostedemail.com: domain of josef@toxicpanda.com has no SPF policy when checking 209.85.222.182) 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=1731356197; 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=+z+eQ7oJzdE2umju6Fr1kTV7qg6yn6q+3nb8dNkk/ko=; b=Xf/TWpFX02RSe3IFFkF6smuhlfMpB/alpsLsZCzfok7o3ndnsSfqTgoB3w6xMDHjQhEBmm 62RefvCA7wvbYE7oIqGflW/1x33kgzAj5eI4nnQWX+RMKaWDkEGAXRrVnAhbNvP28EnlQZ P7BYP9pW4Im8KMsRl185u5P1jlIwdbg= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=toxicpanda-com.20230601.gappssmtp.com header.s=20230601 header.b=DiPyz97R; spf=none (imf08.hostedemail.com: domain of josef@toxicpanda.com has no SPF policy when checking 209.85.222.182) smtp.mailfrom=josef@toxicpanda.com; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1731356197; a=rsa-sha256; cv=none; b=bNjY/RwKjXR1b9gWmP7WiZdOM7IPlzNBAH+roA+4g2WRiPE3i0loqmxToyUbo8MfD4hKPt NeaiSvy2ui51Ug03X1HEk+q3zgcjxY97DnOHMQyVrkwc8YgJikKd7lszR50lOjNQ+JdRO2 ws+2hnknDLSXbBsMW8mT7eaaBrgoJfU= Received: by mail-qk1-f182.google.com with SMTP id af79cd13be357-7b161fa1c7bso325655585a.0 for ; Mon, 11 Nov 2024 12:19:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1731356369; x=1731961169; 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=+z+eQ7oJzdE2umju6Fr1kTV7qg6yn6q+3nb8dNkk/ko=; b=DiPyz97RC+317aabQ8yGGFGzlUJWsQDBqv5s8NZIy4rntfYvLd6fSYZ3JUMhBXWu/F 6UHtk+f2yOZ1/cHTOAYmSdlKA/zi0u+ePEUtWtcuCzV1Yp/yPkfUZS8M7VoeHANJAraI eLe9TNVn5p7UNsfFAGtSKyRPq1Dk85djj6c3xSJrokKRLO1ZfJFcRgFFe+x2t3CvoJKg m7f409GjjApsQ4akLg0BAvBTuLt2JaqlhkzB8+O7OfAfLuvkMMnSUgaLqP3eWUAbOX7b QZWAJ8jyFkFlRjMRwU4advqBUcJyNw6S1/UB96uStcMw+h3aH5KMONg8BStbTrMGb3pA 0AGg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731356369; x=1731961169; 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=+z+eQ7oJzdE2umju6Fr1kTV7qg6yn6q+3nb8dNkk/ko=; b=F+q6uvFVLrpBkYKYloVxtJTGEEVzkv5slTgOkl2352Rtwf24Rl71+8cTYubY7UJQQq Jaz3mBa6SttFf4YAt6sKMCFfQvNaHZFtDfI7tRcVz0+fxrhmW79a7BExWbWqjem4NCNC qVb49PcOEKGX7CtWgcvD7JQbcyZHHSPgrVUSep2mHMSwSfJk6ip1QB2GTSimGk27ZECd RuJGXKcyZnTWjzsSYIivstPRcWFSJelX3aPxta6TEIIWSoAGDkMHlvX2jOdZRL9MsFBx 0uBwj2U7NFkuFCEr+99s3TKhYwU9OYf6S2OmKyY46/X2aaZpKBmGI+g4TD+bn54JyoJL XQjw== X-Forwarded-Encrypted: i=1; AJvYcCVxzhMtXycvHBEcIt94cspWQGFg5eGFsE6lBa8LOGmQM8m8RjJlXEqoNd7lHqzwv2JsjD1+wbZrrQ==@kvack.org X-Gm-Message-State: AOJu0Yz8a+bt8XNGMQIhB4o/00mfCyH96bCpTA2xjn8+7WwjtHUTCR4k bAcj6QYuY9VeCBo9nM75b70R0EcV9MfJsOj2/Cce640y3WfSW0VHXrAC04HPqM4= X-Google-Smtp-Source: AGHT+IGms12DOLEJdB5bkW0IvqVA392HkoYhkn4Pg1bvSAHP7u5Zdmd/IqhCvTQbHrBd1gwbJKpdcw== X-Received: by 2002:a05:620a:179e:b0:7ac:9b5e:baf3 with SMTP id af79cd13be357-7b331eb4c7cmr2112662485a.26.1731356369095; Mon, 11 Nov 2024 12:19:29 -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-7b32acf7f31sm524104585a.129.2024.11.11.12.19.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Nov 2024 12:19:28 -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 12/17] fanotify: disable readahead if we have pre-content watches Date: Mon, 11 Nov 2024 15:18:01 -0500 Message-ID: <983e7415c8d083c7bee0d77e81c87b630f093170.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: D7F55160006 X-Stat-Signature: 81tkinw7e6u8yn8hnqf7h6o83d4zunu1 X-Rspam-User: X-HE-Tag: 1731356342-4550 X-HE-Meta: U2FsdGVkX1+CUOVI2NWWe7DS2SgUH54Zdin3LIOMn1EmXi5h8ft6my2icEcmUzEPjoFl/7C5xa8q8DdaElwAIfRmQMbPI48UJl1bM2v8LCijInCNH1iCUUqigUspOzNIY8ZpRJmG5KKumLKdIEF/drgA8mRezFwRBDh0BZJINL32JS9blAj+NCLh/spA8alFe8KYmEzc0jdwTAIVlAsCkCXFfAKzs6l0LT8WtY6mY4VW/3ckpqfFXTyLZQhCu/AkIG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t0sbbxnXWyEYh71n9RZCkPuefq+Jyr2pGIx8vS3pBecVd/eKipSqPXg= X-Bogosity: Ham, tests=bogofilter, spamicity=0.024849, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: 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 --- mm/filemap.c | 12 ++++++++++++ mm/readahead.c | 13 +++++++++++++ 2 files changed, 25 insertions(+) diff --git a/mm/filemap.c b/mm/filemap.c index 56fa431c52af..fc36a00fa014 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 (fsnotify_file_has_pre_content_watches(file)) + 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 (fsnotify_file_has_pre_content_watches(file)) + 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..9fe678cceba8 100644 --- a/mm/readahead.c +++ b/mm/readahead.c @@ -128,6 +128,7 @@ #include #include #include +#include #include "internal.h" @@ -544,6 +545,14 @@ 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. + */ + if (ractl->file && fsnotify_file_has_pre_content_watches(ractl->file)) + 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 +631,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 && fsnotify_file_has_pre_content_watches(ractl->file)) + return; + /* * Same bit is used for PG_readahead and PG_reclaim. */