From patchwork Wed Sep 4 20:28:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13791371 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 86C8BCD4F24 for ; Wed, 4 Sep 2024 20:30:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C73E56B0185; Wed, 4 Sep 2024 16:29:45 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BD2F46B0188; Wed, 4 Sep 2024 16:29:45 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A22396B0185; Wed, 4 Sep 2024 16:29:45 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 7C0336B0183 for ; Wed, 4 Sep 2024 16:29:45 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 3A37C160369 for ; Wed, 4 Sep 2024 20:29:45 +0000 (UTC) X-FDA: 82528196730.14.642EFF6 Received: from mail-qv1-f48.google.com (mail-qv1-f48.google.com [209.85.219.48]) by imf01.hostedemail.com (Postfix) with ESMTP id 5778E40015 for ; Wed, 4 Sep 2024 20:29:43 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=toxicpanda-com.20230601.gappssmtp.com header.s=20230601 header.b=xdkUy4al; spf=none (imf01.hostedemail.com: domain of josef@toxicpanda.com has no SPF policy when checking 209.85.219.48) 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=1725481686; 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=k2g5nWsdtLhh4I3qKZ9kVR48Zxv3ldXz3E9kfB37E8o=; b=tlDeTWPpDav8pcYLuszR7kPL6GOkHXWvS691Wh2kEKQKJKm5oReL8JpaaxtJTbvkYlftCi pICd2cuiLeLbEHxZJF3hUuwYOVkxn2JgQi7w/qCI5vyZ8yqeh2w1CTaOecrHffwdLCG4bo QB/sybnB670m7Z6W/dZTy393tt2V7M0= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1725481686; a=rsa-sha256; cv=none; b=WXjJAJ6sbP4+vjkCWZP67/67ggTtyJzACbnFlYZcAgFvzEW49H1whe/CN/O62JMK1/uouJ a/U63K34JxkC/0GtSqTYCgjmP7xV84t2m3ydKvL6IThGNuguUF9erccqYcmIkmwDylfQem Ke298lxNuQT/5wAh7NoyN0ZqIIxJhC4= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=toxicpanda-com.20230601.gappssmtp.com header.s=20230601 header.b=xdkUy4al; spf=none (imf01.hostedemail.com: domain of josef@toxicpanda.com has no SPF policy when checking 209.85.219.48) smtp.mailfrom=josef@toxicpanda.com; dmarc=none Received: by mail-qv1-f48.google.com with SMTP id 6a1803df08f44-6c35427935eso30226d6.3 for ; Wed, 04 Sep 2024 13:29:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1725481782; x=1726086582; 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=k2g5nWsdtLhh4I3qKZ9kVR48Zxv3ldXz3E9kfB37E8o=; b=xdkUy4alhyudXtnV05yYnP9O0rgGPXCWpflK6Cbx0PodkhJ11WKTg8aKbvVN+JLnhL ovCcUQZ8jrAZ4SRXvBrbeJ1BudTN2PT1KbaXIMtEJkEiio7K+VZhnaeMO8D8v1EINlKM kYrp8kJb6qpD89XFFrVYMEsjmQUY7lNhSCd1rkUWpIV6w2C6H0ABRW84k1P/eVO2i7cs d6QN0CV6plHhaumy3YNUjT7sPo7FWnHKV4ELOhBb6qG7lBd44Ul/xVgrp2/uGj3tXOQM mGnVgP4w6L/Ayb5kjUiLkefIzWKb8im3j/H++giVWaBZg9wJd6378lma65sc3mUt1EP2 nuAA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725481782; x=1726086582; 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=k2g5nWsdtLhh4I3qKZ9kVR48Zxv3ldXz3E9kfB37E8o=; b=THYP0VpoPHqvkc/mwh2bp2xBPkMOBFXTkCFozgjDnEKWqxnH8255UZlKtGNp38aq1i kuKFcSfKPXoKv+vqrZzUROAzCE0IMkquO4QhRxsfyd8W/CcjA70FxF60C3Lpye2C/fkq xDuTzxxdVJQ0jZ7+dgLUV/U7/Wl19Wo9BZPwIfuKNR3hxF2Hepy4iNusc7Qynj+BUcNA Z57YK8L/9iLgLfYCVWnWr4UHjfUxllNOG50tMLNl7SRkJ92qCLzFqMspMjF3ojzLdqpf xr3eIKqyx+R4Jt16GbVRSpIxt53Fg5IWfJXotrxEbDi8guiHWD1vynAkbM6g0K+tO5B2 FbpQ== X-Forwarded-Encrypted: i=1; AJvYcCWs2auObWIPWNlRmNhCQKinGLKtOnSiRiHUETcVZ/4NAtFk6wPCWWwwf+zthqA51pkDBD/q4SqKww==@kvack.org X-Gm-Message-State: AOJu0YzItp6oAVV7snuNbjjSTxjLhw3M9QePnvxf+ZPU+7Tv/+ks09LQ Ak68jzw1xvVhtTK3IEU7YkUTZdJNL/YJjtMPJqHLKctvcBs8KWb/eOz4tiQpJU4= X-Google-Smtp-Source: AGHT+IGcGqc27V/yp+/MPiFXZlq6o8dH/S56y18i5ffiw87nR/uugOanZlUMV6j8hRmZXaYyxJ0xkA== X-Received: by 2002:a05:6214:4a09:b0:6c3:5ebb:9524 with SMTP id 6a1803df08f44-6c35ebb9733mr193501086d6.48.1725481782473; Wed, 04 Sep 2024 13:29:42 -0700 (PDT) Received: from localhost (syn-076-182-020-124.res.spectrum.com. [76.182.20.124]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6c520419ecfsm1552666d6.126.2024.09.04.13.29.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Sep 2024 13:29:42 -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 17/18] btrfs: disable defrag on pre-content watched files Date: Wed, 4 Sep 2024 16:28:07 -0400 Message-ID: <367fe83ae53839b1e88dc00b5b420035496d28ff.1725481503.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 X-Stat-Signature: orunzh9gppzxqo93w6n5o9u18o4xmkbo X-Rspamd-Queue-Id: 5778E40015 X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1725481783-708665 X-HE-Meta: U2FsdGVkX183agffRDLq2Qe3HEvnbUaNGUOmWZH62MtU0YURJiP+Hh+HpUNTp5XpOtmnzF+ASr2t7ABTGGGTpjStO7lFfwmiCkBzVvB/9HS+RfgCbNj00iCxZHXRPWWC4uIS86/vwwwT9UpsldJHOSF+UD6n9NqWt9NreW7uHHQ6ljSAT4waXUfjJZJW67gqw/BNYYsZzh2O8jZxvTVc6BqbO/dqaTsKZhhlFZ4ulaKy4HwYcQ3oNrlmcGsgix0rr0JV8tb6TFD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fsNR0YmeL9U7nhPdZcWckLB4DvTX8mTawe8d8PKQ= 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: 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 --- fs/btrfs/ioctl.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c index e0a664b8a46a..529f7416814f 100644 --- a/fs/btrfs/ioctl.c +++ b/fs/btrfs/ioctl.c @@ -2640,6 +2640,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 (fsnotify_file_has_pre_content_watches(file)) { + ret = -EINVAL; + goto out; + } + if (argp) { if (copy_from_user(&range, argp, sizeof(range))) { ret = -EFAULT;