From patchwork Mon Nov 11 20:18:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13871234 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 A9386D3ABF5 for ; Mon, 11 Nov 2024 20:19:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7F5656B00A8; Mon, 11 Nov 2024 15:19:40 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 77CAC6B00A9; Mon, 11 Nov 2024 15:19:40 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5D0266B00AA; Mon, 11 Nov 2024 15:19:40 -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 2D6346B00A8 for ; Mon, 11 Nov 2024 15:19:40 -0500 (EST) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id E5DAA140BBB for ; Mon, 11 Nov 2024 20:19:39 +0000 (UTC) X-FDA: 82774929300.28.0092F4C Received: from mail-qk1-f170.google.com (mail-qk1-f170.google.com [209.85.222.170]) by imf26.hostedemail.com (Postfix) with ESMTP id EFB43140010 for ; Mon, 11 Nov 2024 20:19:06 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=toxicpanda-com.20230601.gappssmtp.com header.s=20230601 header.b=cyRfScMC; spf=none (imf26.hostedemail.com: domain of josef@toxicpanda.com has no SPF policy when checking 209.85.222.170) 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=1731356324; 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=qkyyLOcMapxd8eZps50M2cPjgtuAOvBDRyUA+1LsM90=; b=uxs08Fw0SQ+vGFP8GfMu7BdhNzuRc42zgIQcRp6ZxmHKAhBzpexAgRw9u8PQ8C2m7IzLuN ZjzEBPi4t73wDG/XB9RyXrpawC8ANCnhoY4VTIymtHMOKZoNVFSqOyC86r0IuEpLyB0ebE dgIkJ8DHUcXchQr0wcJCFrpop6hR2B8= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1731356324; a=rsa-sha256; cv=none; b=8lOwsIU3/hpk8LmWPFnbJ5X2MOKvGWU1S0UrlGYFXC7qWX9n1GBahhD8TSEKvd7jcwwapv 1jI5Nf94vFmlgw1fB3+fiPKnouioj/kWTF/l/57/9cfRC8K2JNwJ6krySyWPUaubgKwhbP 1YdJDdeS3w7z5ZFumlYvRt+WmvrZ+6o= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=toxicpanda-com.20230601.gappssmtp.com header.s=20230601 header.b=cyRfScMC; spf=none (imf26.hostedemail.com: domain of josef@toxicpanda.com has no SPF policy when checking 209.85.222.170) smtp.mailfrom=josef@toxicpanda.com; dmarc=none Received: by mail-qk1-f170.google.com with SMTP id af79cd13be357-7b1434b00a2so388524085a.0 for ; Mon, 11 Nov 2024 12:19:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1731356377; x=1731961177; 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=qkyyLOcMapxd8eZps50M2cPjgtuAOvBDRyUA+1LsM90=; b=cyRfScMCpAkeTeL/JkmpJkevrTfgUznt8o4N8+N6ekk4GOBQMipgM0OSOZ1kH8Tju9 FNitxd701Age6AZm+n6/Ut/mzHQ/05nTjjbMMA9TMTnuoJCT3Lf1gb1ZLg2c+p88gDgO 4+9+53Wn4RIK8OD5WvfmaTMn45qIgXc2+UtIIffkeBRh+TjBBU1Oik4Moxp6Z/AkMmC0 gZVhwHV3VSDC/TrhZWnjaYfnqcsaChuGAs3WdXroeyZJBfnvAG8BFR9Sx9Z7apImPgeA apoElSndyF3WXAbCIgwsUEsRcP8pVJUv9Tl1G0FSALne7kjxtksBSjuvsMvQli4SFdXN Z7XQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731356377; x=1731961177; 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=qkyyLOcMapxd8eZps50M2cPjgtuAOvBDRyUA+1LsM90=; b=LcvjVxGJPfB/c5XbmdI223eYbYtu/Vdx5OLxOr8KTgcFcgRfbzP73PChbdni/JP3hA mTIxsRGSEBBx3WP5L3udxINDFJfHvTmZ/sv5oLQjzJBgtjMFxkp8bwwW4eTR/DsGpY05 9XIp4WwR6MWaJbFrSZvemoQFqefLA28BRnJ5zvRPND4iIpKsTi9XDtBe+CojwaANaPDR BgYz9a9a1wzDEuF4p7iGr6dwT9t+WKbTykKXeuT9jo70V1VCjyNce8L6pqcYSFIz6hTQ jwUntNY/MCqoeChLn3dSq5cYizGQDdFrmhZLIL5bnEN+jQ9rolyguEyFNsmToytBjmca RneQ== X-Forwarded-Encrypted: i=1; AJvYcCUH889yzWCqR537DsCf91TgX73MCXnEJlnrFiI22Bxl06lrrRHwlYmNIvQEZhvwPlwu7Xqox7E3Eg==@kvack.org X-Gm-Message-State: AOJu0YxuWVNMfOXXp9HqPNcQaA4sCwyc0FBL2sQKOVlWwbP8PBDEx0FA sq+BhtuDSQUrVsDlRLlo2YqEk6xPSsdVfxZ59e+VthglTIfKJJUhVv+cQmJUyws= X-Google-Smtp-Source: AGHT+IGjGL9g3kFfcH+6V8KAtQzfg7b48XSPpKvHKYOiM22WInprVkhEgNc7K8iBcMmLd7E6fsLBYg== X-Received: by 2002:a05:620a:19a7:b0:7b1:3e41:849f with SMTP id af79cd13be357-7b331eff745mr2211412185a.47.1731356377090; Mon, 11 Nov 2024 12:19:37 -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-7b32acae57asm525455685a.81.2024.11.11.12.19.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Nov 2024 12:19:36 -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 16/17] btrfs: disable defrag on pre-content watched files Date: Mon, 11 Nov 2024 15:18:05 -0500 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 X-Stat-Signature: u6rqae3ma5696yi3pp4mcx1yd797xxmw X-Rspam-User: X-Rspamd-Queue-Id: EFB43140010 X-Rspamd-Server: rspam02 X-HE-Tag: 1731356346-210507 X-HE-Meta: U2FsdGVkX19Q2UMk8x8CZCuFzi6QJrTKHH3DYNKWOL1zeA5DFkEkhdDyvkq4NYCdpcEEawBwULeq+CJubmNJlhQRCjMvUvcjSaA3c87WTizfE3rIfk0Ekb9CpMe1NwNe2PEwC/Z0SdtOjT+wpTRoqwdXeclQYwa8fbscYJt6zeALPf1pAb+KP8qknnZsenX32f9OYHeGTc3+gfVsbGFL7Ue+YNcP9FLOYi/eGKz6pEAj9lxjqzTKVLsBT7CXlkbtQLt8BJt9wC/s47PrR6VSVgSgoC0AtJg3g+QFNYuYKRvmEX1iauO5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Ham, tests=bogofilter, spamicity=0.000040, 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 226c91fe31a7..9b13df1ea729 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 (fsnotify_file_has_pre_content_watches(file)) { + ret = -EINVAL; + goto out; + } + if (argp) { if (copy_from_user(&range, argp, sizeof(range))) { ret = -EFAULT;