From patchwork Thu Nov 21 11:22:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kara X-Patchwork-Id: 13881881 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 2E605D6ED0C for ; Thu, 21 Nov 2024 11:23:06 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E34EE6B00A1; Thu, 21 Nov 2024 06:22:32 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id C60B66B0099; 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 4C0256B009C; Thu, 21 Nov 2024 06:22:32 -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 C42D06B00A0 for ; Thu, 21 Nov 2024 06:22:31 -0500 (EST) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 830281C7839 for ; Thu, 21 Nov 2024 11:22:31 +0000 (UTC) X-FDA: 82809861372.07.8C8ACC9 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) by imf24.hostedemail.com (Postfix) with ESMTP id 81D6E180002 for ; Thu, 21 Nov 2024 11:22:22 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b="gwyp/tiu"; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=6rhH2MkM; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b="gwyp/tiu"; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=6rhH2MkM; spf=pass (imf24.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=1732187945; 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=ES82s1Ri3LKq9EL11F8KNpqRIlXam9IZ5netWZvoqAk=; b=IMLUMEa2tDRcTlnxbO8i1bVrwA6fFRbWLcGou1praph5teZUBHAF+HAE32SYpLm2dvML9+ +dIXYlVpIp7VhWVPSFdyj0L1lmgbM1yCfffkBFq8zJWYFnd7WLP1NCJSWSKWDqjFBn3yP0 DCaD2+pck66ypaj1bojchsHcBtfSLwk= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b="gwyp/tiu"; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=6rhH2MkM; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b="gwyp/tiu"; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=6rhH2MkM; spf=pass (imf24.hostedemail.com: domain of jack@suse.cz designates 195.135.223.130 as permitted sender) smtp.mailfrom=jack@suse.cz; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1732187945; a=rsa-sha256; cv=none; b=VQORZXFvEI0a289L9ouYxJse7PNlleCdgaOdJ1ntM0Z833ajnGhgJ3c/RaQPey+HzjugSi /Z1ChBkWV3R9X74vHHHb2Gvzc8xPmxcjUTomiSBPvDhiD2AkcTZHyv0q2qJ9Df4iew7Xq7 6eM7SFMetSkLjo61gpaShoVJ7FjMgAA= 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 BF8A721A07; 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=ES82s1Ri3LKq9EL11F8KNpqRIlXam9IZ5netWZvoqAk=; b=gwyp/tiuCorqHKw30CrvpaG3bM521seihwVZ9+I53W3/04UUglT5QPXaUVDdrPLw2dtptU RJIzHcd8nOZa/Kk+OYxhokM2EWRJ/YKZWN2bYCviDnYW8R3eYYz+3wuUNJ/bUyoHdL7HFj w72vjEQe2yIvw4L7kwSHaqKayhCwwT4= 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=ES82s1Ri3LKq9EL11F8KNpqRIlXam9IZ5netWZvoqAk=; b=6rhH2MkMVU24YBhu26kbxGPJjyAavqg40Q1UFGLkgcMytyCIW/J3NUAQU/uJcqi9gyxvoS nqYdFwwHqi6D6gCw== 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=ES82s1Ri3LKq9EL11F8KNpqRIlXam9IZ5netWZvoqAk=; b=gwyp/tiuCorqHKw30CrvpaG3bM521seihwVZ9+I53W3/04UUglT5QPXaUVDdrPLw2dtptU RJIzHcd8nOZa/Kk+OYxhokM2EWRJ/YKZWN2bYCviDnYW8R3eYYz+3wuUNJ/bUyoHdL7HFj w72vjEQe2yIvw4L7kwSHaqKayhCwwT4= 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=ES82s1Ri3LKq9EL11F8KNpqRIlXam9IZ5netWZvoqAk=; b=6rhH2MkMVU24YBhu26kbxGPJjyAavqg40Q1UFGLkgcMytyCIW/J3NUAQU/uJcqi9gyxvoS nqYdFwwHqi6D6gCw== 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 B4A5513A23; 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 DuYZLPAXP2dJfwAAD6G6ig (envelope-from ); Thu, 21 Nov 2024 11:22:24 +0000 Received: by quack3.suse.cz (Postfix, from userid 1000) id 51766A0930; 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 17/19] btrfs: disable defrag on pre-content watched files Date: Thu, 21 Nov 2024 12:22:16 +0100 Message-Id: <20241121112218.8249-18-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-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 81D6E180002 X-Stat-Signature: pb38refj4nbjph34nsmf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hjck7DSNEpiLGjussvHRlz533bPh1Mzwj8/3d6ssC7gP+Y/7ZhchuAL1seJVAy1hOIw0UaKoA2HMyWkHkElrClF6cbGdmfR18ZdSnHr0EwRpiJRRferyDiZ0gg8r2NX0eaecfWUSH/oN9A0Up33t6M/fbN3lLBZYjp8BmWl5IooUU8vtoP33A9t3XH8hFc544Ji8wXaxcl81gL82o3eOyqHS27aG6dyl5EjBH6M9PB8QnvKRiBrk58O5n5JX+t86yd+wz83Q5ksEolsSfAPR3408Ys2EcoF7Vh/vajiZnctPC3i3HTtjPGOkpjHbGQLWu9a0dlhp1xO3b/URkwwUk1GRxSV 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 We queue up inodes to be defrag'ed asynchronously, which means we do not have their original file for readahead. This means that the code to skip readahead on pre-content watched files will not run, and we could potentially read in empty pages. Handle this corner case by disabling defrag on files that are currently being watched for pre-content events. Signed-off-by: Josef Bacik Signed-off-by: Jan Kara Link: https://patch.msgid.link/4cc5bcea13db7904174353d08e85157356282a59.1731684329.git.josef@toxicpanda.com --- fs/btrfs/ioctl.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c index 226c91fe31a7..a908f75458f0 100644 --- a/fs/btrfs/ioctl.c +++ b/fs/btrfs/ioctl.c @@ -2638,6 +2638,15 @@ static int btrfs_ioctl_defrag(struct file *file, void __user *argp) goto out; } + /* + * Don't allow defrag on pre-content watched files, as it could + * populate the page cache with 0's via readahead. + */ + if (unlikely(FMODE_FSNOTIFY_HSM(file->f_mode))) { + ret = -EINVAL; + goto out; + } + if (argp) { if (copy_from_user(&range, argp, sizeof(range))) { ret = -EFAULT;