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: 13881921 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B6D171DA11A; Thu, 21 Nov 2024 11:22:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.130 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732188153; cv=none; b=XgtqflnUu6Ipnw799txdgp+eH/lDMe8XGsY4+T+G0ydoSS+R7EK0vG+oD3hLHDFSNcgnS3svK4qA5zbvV66LCL7nrJcSHwiCq14EKEO124VQLjAYAGYoR0j+cl/38VaEHYVH+84Iwe9Za0gG9BjlKk4OampoA3CRLp5sSIJvFq0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732188153; c=relaxed/simple; bh=GEwnlrOiMu0h7O6NSVhM5VwSkR2ma9htqafS2JvmCdk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=HZJJCxZflvYYuJUynJxwrCRM3L8dq5yt+BmFakejcGfPZ0IXexRd9i8448WrMLEFMVH8Ri3qv+TYljAq1SzGO62tODRcHdArdAkUTbYzo3N2ChbxVAhaRYlto7i/mLu4DZCWr0uSCNkd4XeRYQi6SpqIRa9FZHK/ZN0TUXeBFUw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=suse.cz; spf=pass smtp.mailfrom=suse.cz; dkim=pass (1024-bit key) header.d=suse.cz header.i=@suse.cz header.b=gwyp/tiu; dkim=permerror (0-bit key) header.d=suse.cz header.i=@suse.cz header.b=6rhH2MkM; dkim=pass (1024-bit key) header.d=suse.cz header.i=@suse.cz header.b=gwyp/tiu; dkim=permerror (0-bit key) header.d=suse.cz header.i=@suse.cz header.b=6rhH2MkM; arc=none smtp.client-ip=195.135.223.130 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.cz Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.cz header.i=@suse.cz header.b="gwyp/tiu"; dkim=permerror (0-bit key) header.d=suse.cz header.i=@suse.cz header.b="6rhH2MkM"; dkim=pass (1024-bit key) header.d=suse.cz header.i=@suse.cz header.b="gwyp/tiu"; dkim=permerror (0-bit key) header.d=suse.cz header.i=@suse.cz header.b="6rhH2MkM" 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== Authentication-Results: smtp-out1.suse.de; none 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> Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Score: -6.80 X-Spamd-Result: default: False [-6.80 / 50.00]; REPLY(-4.00)[]; BAYES_HAM(-3.00)[99.99%]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_MISSING_CHARSET(0.50)[]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; ARC_NA(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_VIA_SMTP_AUTH(0.00)[]; TO_DN_SOME(0.00)[]; RCPT_COUNT_SEVEN(0.00)[11]; RCVD_COUNT_THREE(0.00)[3]; DKIM_SIGNED(0.00)[suse.cz:s=susede2_rsa,suse.cz:s=susede2_ed25519]; FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[]; FREEMAIL_CC(0.00)[gmail.com,toxicpanda.com,kernel.org,linux-foundation.org,ZenIV.linux.org.uk,vger.kernel.org,kvack.org,suse.cz]; R_RATELIMIT(0.00)[to_ip_from(RLdu9otajk16idfrkma9mbkf9b)]; DBL_BLOCKED_OPENRESOLVER(0.00)[msgid.link:url,imap1.dmz-prg2.suse.org:helo]; RCVD_TLS_LAST(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; FUZZY_BLOCKED(0.00)[rspamd.com]; FREEMAIL_ENVRCPT(0.00)[gmail.com] X-Spam-Flag: NO X-Spam-Level: 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;