Message ID | 20230420004850.297045-2-sarthakkukreti@chromium.org |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp766706vqo; Wed, 19 Apr 2023 17:50:19 -0700 (PDT) X-Google-Smtp-Source: AKy350Ymzef3eA+aHQXePWuNOPbsI/F2jF0nkb7Ndzb7chQXt++lg6//kNdm9W/SVMEL3eixMMUJ X-Received: by 2002:a17:902:c94f:b0:1a6:dc4a:b8fa with SMTP id i15-20020a170902c94f00b001a6dc4ab8famr8288384pla.54.1681951819564; Wed, 19 Apr 2023 17:50:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681951819; cv=none; d=google.com; s=arc-20160816; b=yy12lcjd4ZUpQyzbidYPumO1x8VN5tbDaq9U3kRyPVQiSb6/sey6QknPql+gRMNlNh b3mer4C8OO75IsKsOt4yTL4S42/ikRR1koY2ofVqtslak43ny4vdmX7xpFqCpyji3qKY MmqrD0EsnUHN1Npx8/RuiGnPR9uWUfiawsw14z3b3iiNyKm6tJkztvJMAHuFMx2Mb0Lf rJMuQL8kyiEDv3aiPb2DAu7uqnZvXGF94wwxRNZD9Ie8B9JcqeV2rPuaiZgKmSBmOjc7 t1gfCZIdoN8+RykIbs2xUTKCDm9F4vRUR1SRd42TlIKkWy5mfQdvHrqJ/JN9FKotmCDT ZYew== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=G8Jg49/KQsZt4WzBpHKtXWTZpexlXZcV39964TwtkKY=; b=xQ6nnatIaX/HUZCL+VhvvQ7Bx+PRcSpGNvc0/Yw2hUn3F5x2NzQ50vZcoGorEuE9nM 7KDpvurEZvy8VECkQ/Rn4YXTZGnzIk05sQWhdiA47nAv7+Kp+2cexf8FykxAHAuIfCwJ AY8ESGxB6dGM7KLLOIQyaZTAcLq6o5diTuLVZ88Q45SlxfJhZZVsDhEy0C+2crhQta4E QtjPmTLJsyWD4CZPjHmLK8SP6q1wXSfFzsjxTj0kNZZ4sQdyTQvUE9xTjbjOjJxseeDS UG3jZm3FvaPmU51IVdvrPAsRgsY1zyAIhpLSZugxfbCKDt1ay1BoIi46Zb6Xr7tXvXQN 9msQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b="Q4O+/LqS"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d9-20020a170903230900b001a63a2de59asi177782plh.494.2023.04.19.17.50.03; Wed, 19 Apr 2023 17:50:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b="Q4O+/LqS"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232367AbjDTAtH (ORCPT <rfc822;peter110.wang@gmail.com> + 99 others); Wed, 19 Apr 2023 20:49:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48584 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232395AbjDTAtA (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Wed, 19 Apr 2023 20:49:00 -0400 Received: from mail-pl1-x634.google.com (mail-pl1-x634.google.com [IPv6:2607:f8b0:4864:20::634]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ABCAF3AAA for <linux-kernel@vger.kernel.org>; Wed, 19 Apr 2023 17:48:57 -0700 (PDT) Received: by mail-pl1-x634.google.com with SMTP id d9443c01a7336-1a677dffb37so5344145ad.2 for <linux-kernel@vger.kernel.org>; Wed, 19 Apr 2023 17:48:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1681951737; x=1684543737; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=G8Jg49/KQsZt4WzBpHKtXWTZpexlXZcV39964TwtkKY=; b=Q4O+/LqSIe1dsLzJhrazbt5goLnGi1zJWJbTolX3hoDJhRdiYIt8oP3uueEYErY/Me zQFFkE4rPiCEQLA8DNT5eqI7xXNcKG9o07MjxHnnVHAWwiIa2Rlq84+FMrIzrcymDMj0 zmTM8yrT7jralZt9fyBveGGYaxRpJ9r5tkzj0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681951737; x=1684543737; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=G8Jg49/KQsZt4WzBpHKtXWTZpexlXZcV39964TwtkKY=; b=eInOhfbcyD3L5tEEPLz+Ek5ZldT05zYOiAJMZNDWDw4hfVtUNHxmud2ztnWDB4vLWg ooD60PJf8D5SAUVxsd3q4tUc0bSjBDbfOydbc3+0DAImmLFWOyykJXW+LVVrUS0kjT3x was1QTXiCnMhcQnhUmiH4dtVG7ilqQf0NvTrzVPLIs4GyQVMqqmM/LNm58Wx6k5CxRWB RzgbpmwpEAsqy5u9OwZqyjRVLuWUk8RB67J4y2j4fEqnRYuiB42TM+wQiX/JPUyO/aD1 v+DJpaDCnJ0GMJMYuITMff8D5vZob7mJ3rYX6d4YZqhr0GC+InSBsnOCareoaWN3OPh7 qTbg== X-Gm-Message-State: AAQBX9eZ1JaPrCAcf0+dXEHowp+8lBGRJZ8Gk6WA7U+yay274UbEQLoO iRQHxyWR4TvmLOq0/upY98lvjQ== X-Received: by 2002:a17:902:ea0f:b0:19c:b11b:ffca with SMTP id s15-20020a170902ea0f00b0019cb11bffcamr8862265plg.23.1681951736959; Wed, 19 Apr 2023 17:48:56 -0700 (PDT) Received: from sarthakkukreti-glaptop.corp.google.com ([2620:15c:9d:200:5113:a333:10ce:e2d]) by smtp.gmail.com with ESMTPSA id io18-20020a17090312d200b001a65575c13asm74323plb.48.2023.04.19.17.48.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Apr 2023 17:48:56 -0700 (PDT) From: Sarthak Kukreti <sarthakkukreti@chromium.org> To: dm-devel@redhat.com, linux-block@vger.kernel.org, linux-ext4@vger.kernel.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org Cc: Jens Axboe <axboe@kernel.dk>, "Michael S. Tsirkin" <mst@redhat.com>, Jason Wang <jasowang@redhat.com>, Stefan Hajnoczi <stefanha@redhat.com>, Alasdair Kergon <agk@redhat.com>, Mike Snitzer <snitzer@kernel.org>, Christoph Hellwig <hch@infradead.org>, Brian Foster <bfoster@redhat.com>, Theodore Ts'o <tytso@mit.edu>, Andreas Dilger <adilger.kernel@dilger.ca>, Bart Van Assche <bvanassche@google.com>, Daniil Lunev <dlunev@google.com>, "Darrick J. Wong" <djwong@kernel.org> Subject: [PATCH v5 1/5] block: Don't invalidate pagecache for invalid falloc modes Date: Wed, 19 Apr 2023 17:48:46 -0700 Message-ID: <20230420004850.297045-2-sarthakkukreti@chromium.org> X-Mailer: git-send-email 2.40.0.634.g4ca3ef3211-goog In-Reply-To: <20230420004850.297045-1-sarthakkukreti@chromium.org> References: <20230414000219.92640-1-sarthakkukreti@chromium.org> <20230420004850.297045-1-sarthakkukreti@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1763654311175180849?= X-GMAIL-MSGID: =?utf-8?q?1763654311175180849?= |
Series |
Introduce block provisioning primitives
|
|
Commit Message
Sarthak Kukreti
April 20, 2023, 12:48 a.m. UTC
Only call truncate_bdev_range() if the fallocate mode is
supported. This fixes a bug where data in the pagecache
could be invalidated if the fallocate() was called on the
block device with an invalid mode.
Fixes: 25f4c41415e5 ("block: implement (some of) fallocate for block devices")
Signed-off-by: Sarthak Kukreti <sarthakkukreti@chromium.org>
---
block/fops.c | 18 ++++++++++--------
1 file changed, 10 insertions(+), 8 deletions(-)
Comments
On Wed, Apr 19, 2023 at 05:48:46PM -0700, Sarthak Kukreti wrote: > Only call truncate_bdev_range() if the fallocate mode is > supported. This fixes a bug where data in the pagecache > could be invalidated if the fallocate() was called on the > block device with an invalid mode. > > Fixes: 25f4c41415e5 ("block: implement (some of) fallocate for block devices") > Signed-off-by: Sarthak Kukreti <sarthakkukreti@chromium.org> > --- > block/fops.c | 18 ++++++++++-------- > 1 file changed, 10 insertions(+), 8 deletions(-) > > diff --git a/block/fops.c b/block/fops.c > index d2e6be4e3d1c..2fd7e8b9ab48 100644 > --- a/block/fops.c > +++ b/block/fops.c > @@ -648,25 +648,27 @@ static long blkdev_fallocate(struct file *file, int mode, loff_t start, > > filemap_invalidate_lock(inode->i_mapping); > > - /* Invalidate the page cache, including dirty pages. */ > - error = truncate_bdev_range(bdev, file->f_mode, start, end); > - if (error) > - goto fail; > - > + /* > + * Invalidate the page cache, including dirty pages, for valid > + * de-allocate mode calls to fallocate(). > + */ > switch (mode) { > case FALLOC_FL_ZERO_RANGE: > case FALLOC_FL_ZERO_RANGE | FALLOC_FL_KEEP_SIZE: > - error = blkdev_issue_zeroout(bdev, start >> SECTOR_SHIFT, > + error = truncate_bdev_range(bdev, file->f_mode, start, end) || > + blkdev_issue_zeroout(bdev, start >> SECTOR_SHIFT, I'm pretty sure we're supposed to preserve the error codes returned by both functions. error = truncate_bdev_range(...); if (!error) error = blkdev_issue_zeroout(...); --D > len >> SECTOR_SHIFT, GFP_KERNEL, > BLKDEV_ZERO_NOUNMAP); > break; > case FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE: > - error = blkdev_issue_zeroout(bdev, start >> SECTOR_SHIFT, > + error = truncate_bdev_range(bdev, file->f_mode, start, end) || > + blkdev_issue_zeroout(bdev, start >> SECTOR_SHIFT, > len >> SECTOR_SHIFT, GFP_KERNEL, > BLKDEV_ZERO_NOFALLBACK); > break; > case FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE | FALLOC_FL_NO_HIDE_STALE: > - error = blkdev_issue_discard(bdev, start >> SECTOR_SHIFT, > + error = truncate_bdev_range(bdev, file->f_mode, start, end) || > + blkdev_issue_discard(bdev, start >> SECTOR_SHIFT, > len >> SECTOR_SHIFT, GFP_KERNEL); > break; > default: > -- > 2.40.0.634.g4ca3ef3211-goog >
Sorry I tried to be too concise :) Updated with a fixed up patch! Best Sarhtak On Wed, Apr 19, 2023 at 6:22 PM Darrick J. Wong <djwong@kernel.org> wrote: > > On Wed, Apr 19, 2023 at 05:48:46PM -0700, Sarthak Kukreti wrote: > > Only call truncate_bdev_range() if the fallocate mode is > > supported. This fixes a bug where data in the pagecache > > could be invalidated if the fallocate() was called on the > > block device with an invalid mode. > > > > Fixes: 25f4c41415e5 ("block: implement (some of) fallocate for block devices") > > Signed-off-by: Sarthak Kukreti <sarthakkukreti@chromium.org> > > --- > > block/fops.c | 18 ++++++++++-------- > > 1 file changed, 10 insertions(+), 8 deletions(-) > > > > diff --git a/block/fops.c b/block/fops.c > > index d2e6be4e3d1c..2fd7e8b9ab48 100644 > > --- a/block/fops.c > > +++ b/block/fops.c > > @@ -648,25 +648,27 @@ static long blkdev_fallocate(struct file *file, int mode, loff_t start, > > > > filemap_invalidate_lock(inode->i_mapping); > > > > - /* Invalidate the page cache, including dirty pages. */ > > - error = truncate_bdev_range(bdev, file->f_mode, start, end); > > - if (error) > > - goto fail; > > - > > + /* > > + * Invalidate the page cache, including dirty pages, for valid > > + * de-allocate mode calls to fallocate(). > > + */ > > switch (mode) { > > case FALLOC_FL_ZERO_RANGE: > > case FALLOC_FL_ZERO_RANGE | FALLOC_FL_KEEP_SIZE: > > - error = blkdev_issue_zeroout(bdev, start >> SECTOR_SHIFT, > > + error = truncate_bdev_range(bdev, file->f_mode, start, end) || > > + blkdev_issue_zeroout(bdev, start >> SECTOR_SHIFT, > > I'm pretty sure we're supposed to preserve the error codes returned by > both functions. > > error = truncate_bdev_range(...); > if (!error) > error = blkdev_issue_zeroout(...); > > --D > > > len >> SECTOR_SHIFT, GFP_KERNEL, > > BLKDEV_ZERO_NOUNMAP); > > break; > > case FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE: > > - error = blkdev_issue_zeroout(bdev, start >> SECTOR_SHIFT, > > + error = truncate_bdev_range(bdev, file->f_mode, start, end) || > > + blkdev_issue_zeroout(bdev, start >> SECTOR_SHIFT, > > len >> SECTOR_SHIFT, GFP_KERNEL, > > BLKDEV_ZERO_NOFALLBACK); > > break; > > case FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE | FALLOC_FL_NO_HIDE_STALE: > > - error = blkdev_issue_discard(bdev, start >> SECTOR_SHIFT, > > + error = truncate_bdev_range(bdev, file->f_mode, start, end) || > > + blkdev_issue_discard(bdev, start >> SECTOR_SHIFT, > > len >> SECTOR_SHIFT, GFP_KERNEL); > > break; > > default: > > -- > > 2.40.0.634.g4ca3ef3211-goog > >
Hi Sarthak,
kernel test robot noticed the following build warnings:
[auto build test WARNING on device-mapper-dm/for-next]
[also build test WARNING on linus/master v6.3 next-20230421]
[cannot apply to axboe-block/for-next]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Sarthak-Kukreti/block-Introduce-provisioning-primitives/20230420-095025
base: https://git.kernel.org/pub/scm/linux/kernel/git/device-mapper/linux-dm.git for-next
patch link: https://lore.kernel.org/r/20230420004850.297045-2-sarthakkukreti%40chromium.org
patch subject: [PATCH v5 1/5] block: Don't invalidate pagecache for invalid falloc modes
config: hexagon-randconfig-r006-20230424 (https://download.01.org/0day-ci/archive/20230424/202304242302.5zYRfUub-lkp@intel.com/config)
compiler: clang version 17.0.0 (https://github.com/llvm/llvm-project 437b7602e4a998220871de78afcb020b9c14a661)
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# https://github.com/intel-lab-lkp/linux/commit/8bd0744b438be1722c5f8c1fe077e9dcef0e81b7
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Sarthak-Kukreti/block-Introduce-provisioning-primitives/20230420-095025
git checkout 8bd0744b438be1722c5f8c1fe077e9dcef0e81b7
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=hexagon olddefconfig
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=hexagon SHELL=/bin/bash
If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <lkp@intel.com>
| Link: https://lore.kernel.org/oe-kbuild-all/202304242302.5zYRfUub-lkp@intel.com/
All warnings (new ones prefixed by >>):
In file included from block/fops.c:9:
In file included from include/linux/blkdev.h:9:
In file included from include/linux/blk_types.h:10:
In file included from include/linux/bvec.h:10:
In file included from include/linux/highmem.h:12:
In file included from include/linux/hardirq.h:11:
In file included from ./arch/hexagon/include/generated/asm/hardirq.h:1:
In file included from include/asm-generic/hardirq.h:17:
In file included from include/linux/irq.h:20:
In file included from include/linux/io.h:13:
In file included from arch/hexagon/include/asm/io.h:334:
include/asm-generic/io.h:547:31: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
val = __raw_readb(PCI_IOBASE + addr);
~~~~~~~~~~ ^
include/asm-generic/io.h:560:61: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
val = __le16_to_cpu((__le16 __force)__raw_readw(PCI_IOBASE + addr));
~~~~~~~~~~ ^
include/uapi/linux/byteorder/little_endian.h:37:51: note: expanded from macro '__le16_to_cpu'
#define __le16_to_cpu(x) ((__force __u16)(__le16)(x))
^
In file included from block/fops.c:9:
In file included from include/linux/blkdev.h:9:
In file included from include/linux/blk_types.h:10:
In file included from include/linux/bvec.h:10:
In file included from include/linux/highmem.h:12:
In file included from include/linux/hardirq.h:11:
In file included from ./arch/hexagon/include/generated/asm/hardirq.h:1:
In file included from include/asm-generic/hardirq.h:17:
In file included from include/linux/irq.h:20:
In file included from include/linux/io.h:13:
In file included from arch/hexagon/include/asm/io.h:334:
include/asm-generic/io.h:573:61: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
val = __le32_to_cpu((__le32 __force)__raw_readl(PCI_IOBASE + addr));
~~~~~~~~~~ ^
include/uapi/linux/byteorder/little_endian.h:35:51: note: expanded from macro '__le32_to_cpu'
#define __le32_to_cpu(x) ((__force __u32)(__le32)(x))
^
In file included from block/fops.c:9:
In file included from include/linux/blkdev.h:9:
In file included from include/linux/blk_types.h:10:
In file included from include/linux/bvec.h:10:
In file included from include/linux/highmem.h:12:
In file included from include/linux/hardirq.h:11:
In file included from ./arch/hexagon/include/generated/asm/hardirq.h:1:
In file included from include/asm-generic/hardirq.h:17:
In file included from include/linux/irq.h:20:
In file included from include/linux/io.h:13:
In file included from arch/hexagon/include/asm/io.h:334:
include/asm-generic/io.h:584:33: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
__raw_writeb(value, PCI_IOBASE + addr);
~~~~~~~~~~ ^
include/asm-generic/io.h:594:59: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
__raw_writew((u16 __force)cpu_to_le16(value), PCI_IOBASE + addr);
~~~~~~~~~~ ^
include/asm-generic/io.h:604:59: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
__raw_writel((u32 __force)cpu_to_le32(value), PCI_IOBASE + addr);
~~~~~~~~~~ ^
>> block/fops.c:678:2: warning: unused label 'fail' [-Wunused-label]
fail:
^~~~~
7 warnings generated.
vim +/fail +678 block/fops.c
cd82cca7ebfe9c Christoph Hellwig 2021-09-07 613
cd82cca7ebfe9c Christoph Hellwig 2021-09-07 614 #define BLKDEV_FALLOC_FL_SUPPORTED \
cd82cca7ebfe9c Christoph Hellwig 2021-09-07 615 (FALLOC_FL_KEEP_SIZE | FALLOC_FL_PUNCH_HOLE | \
cd82cca7ebfe9c Christoph Hellwig 2021-09-07 616 FALLOC_FL_ZERO_RANGE | FALLOC_FL_NO_HIDE_STALE)
cd82cca7ebfe9c Christoph Hellwig 2021-09-07 617
cd82cca7ebfe9c Christoph Hellwig 2021-09-07 618 static long blkdev_fallocate(struct file *file, int mode, loff_t start,
cd82cca7ebfe9c Christoph Hellwig 2021-09-07 619 loff_t len)
cd82cca7ebfe9c Christoph Hellwig 2021-09-07 620 {
f278eb3d8178f9 Ming Lei 2021-09-23 621 struct inode *inode = bdev_file_inode(file);
f278eb3d8178f9 Ming Lei 2021-09-23 622 struct block_device *bdev = I_BDEV(inode);
cd82cca7ebfe9c Christoph Hellwig 2021-09-07 623 loff_t end = start + len - 1;
cd82cca7ebfe9c Christoph Hellwig 2021-09-07 624 loff_t isize;
cd82cca7ebfe9c Christoph Hellwig 2021-09-07 625 int error;
cd82cca7ebfe9c Christoph Hellwig 2021-09-07 626
cd82cca7ebfe9c Christoph Hellwig 2021-09-07 627 /* Fail if we don't recognize the flags. */
cd82cca7ebfe9c Christoph Hellwig 2021-09-07 628 if (mode & ~BLKDEV_FALLOC_FL_SUPPORTED)
cd82cca7ebfe9c Christoph Hellwig 2021-09-07 629 return -EOPNOTSUPP;
cd82cca7ebfe9c Christoph Hellwig 2021-09-07 630
cd82cca7ebfe9c Christoph Hellwig 2021-09-07 631 /* Don't go off the end of the device. */
2a93ad8fcb377b Christoph Hellwig 2021-10-18 632 isize = bdev_nr_bytes(bdev);
cd82cca7ebfe9c Christoph Hellwig 2021-09-07 633 if (start >= isize)
cd82cca7ebfe9c Christoph Hellwig 2021-09-07 634 return -EINVAL;
cd82cca7ebfe9c Christoph Hellwig 2021-09-07 635 if (end >= isize) {
cd82cca7ebfe9c Christoph Hellwig 2021-09-07 636 if (mode & FALLOC_FL_KEEP_SIZE) {
cd82cca7ebfe9c Christoph Hellwig 2021-09-07 637 len = isize - start;
cd82cca7ebfe9c Christoph Hellwig 2021-09-07 638 end = start + len - 1;
cd82cca7ebfe9c Christoph Hellwig 2021-09-07 639 } else
cd82cca7ebfe9c Christoph Hellwig 2021-09-07 640 return -EINVAL;
cd82cca7ebfe9c Christoph Hellwig 2021-09-07 641 }
cd82cca7ebfe9c Christoph Hellwig 2021-09-07 642
cd82cca7ebfe9c Christoph Hellwig 2021-09-07 643 /*
cd82cca7ebfe9c Christoph Hellwig 2021-09-07 644 * Don't allow IO that isn't aligned to logical block size.
cd82cca7ebfe9c Christoph Hellwig 2021-09-07 645 */
cd82cca7ebfe9c Christoph Hellwig 2021-09-07 646 if ((start | len) & (bdev_logical_block_size(bdev) - 1))
cd82cca7ebfe9c Christoph Hellwig 2021-09-07 647 return -EINVAL;
cd82cca7ebfe9c Christoph Hellwig 2021-09-07 648
f278eb3d8178f9 Ming Lei 2021-09-23 649 filemap_invalidate_lock(inode->i_mapping);
f278eb3d8178f9 Ming Lei 2021-09-23 650
8bd0744b438be1 Sarthak Kukreti 2023-04-19 651 /*
8bd0744b438be1 Sarthak Kukreti 2023-04-19 652 * Invalidate the page cache, including dirty pages, for valid
8bd0744b438be1 Sarthak Kukreti 2023-04-19 653 * de-allocate mode calls to fallocate().
8bd0744b438be1 Sarthak Kukreti 2023-04-19 654 */
cd82cca7ebfe9c Christoph Hellwig 2021-09-07 655 switch (mode) {
cd82cca7ebfe9c Christoph Hellwig 2021-09-07 656 case FALLOC_FL_ZERO_RANGE:
cd82cca7ebfe9c Christoph Hellwig 2021-09-07 657 case FALLOC_FL_ZERO_RANGE | FALLOC_FL_KEEP_SIZE:
8bd0744b438be1 Sarthak Kukreti 2023-04-19 658 error = truncate_bdev_range(bdev, file->f_mode, start, end) ||
8bd0744b438be1 Sarthak Kukreti 2023-04-19 659 blkdev_issue_zeroout(bdev, start >> SECTOR_SHIFT,
6549a874fb65e7 Pavel Begunkov 2021-10-20 660 len >> SECTOR_SHIFT, GFP_KERNEL,
6549a874fb65e7 Pavel Begunkov 2021-10-20 661 BLKDEV_ZERO_NOUNMAP);
cd82cca7ebfe9c Christoph Hellwig 2021-09-07 662 break;
cd82cca7ebfe9c Christoph Hellwig 2021-09-07 663 case FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE:
8bd0744b438be1 Sarthak Kukreti 2023-04-19 664 error = truncate_bdev_range(bdev, file->f_mode, start, end) ||
8bd0744b438be1 Sarthak Kukreti 2023-04-19 665 blkdev_issue_zeroout(bdev, start >> SECTOR_SHIFT,
6549a874fb65e7 Pavel Begunkov 2021-10-20 666 len >> SECTOR_SHIFT, GFP_KERNEL,
6549a874fb65e7 Pavel Begunkov 2021-10-20 667 BLKDEV_ZERO_NOFALLBACK);
cd82cca7ebfe9c Christoph Hellwig 2021-09-07 668 break;
cd82cca7ebfe9c Christoph Hellwig 2021-09-07 669 case FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE | FALLOC_FL_NO_HIDE_STALE:
8bd0744b438be1 Sarthak Kukreti 2023-04-19 670 error = truncate_bdev_range(bdev, file->f_mode, start, end) ||
8bd0744b438be1 Sarthak Kukreti 2023-04-19 671 blkdev_issue_discard(bdev, start >> SECTOR_SHIFT,
44abff2c0b970a Christoph Hellwig 2022-04-15 672 len >> SECTOR_SHIFT, GFP_KERNEL);
cd82cca7ebfe9c Christoph Hellwig 2021-09-07 673 break;
cd82cca7ebfe9c Christoph Hellwig 2021-09-07 674 default:
f278eb3d8178f9 Ming Lei 2021-09-23 675 error = -EOPNOTSUPP;
cd82cca7ebfe9c Christoph Hellwig 2021-09-07 676 }
cd82cca7ebfe9c Christoph Hellwig 2021-09-07 677
f278eb3d8178f9 Ming Lei 2021-09-23 @678 fail:
f278eb3d8178f9 Ming Lei 2021-09-23 679 filemap_invalidate_unlock(inode->i_mapping);
f278eb3d8178f9 Ming Lei 2021-09-23 680 return error;
cd82cca7ebfe9c Christoph Hellwig 2021-09-07 681 }
cd82cca7ebfe9c Christoph Hellwig 2021-09-07 682
Hello, kernel test robot noticed "xfstests.generic.351.fail" on: commit: 8bd0744b438be1722c5f8c1fe077e9dcef0e81b7 ("[PATCH v5 1/5] block: Don't invalidate pagecache for invalid falloc modes") url: https://github.com/intel-lab-lkp/linux/commits/Sarthak-Kukreti/block-Introduce-provisioning-primitives/20230420-095025 base: https://git.kernel.org/cgit/linux/kernel/git/device-mapper/linux-dm.git for-next patch link: https://lore.kernel.org/all/20230420004850.297045-2-sarthakkukreti@chromium.org/ patch subject: [PATCH v5 1/5] block: Don't invalidate pagecache for invalid falloc modes in testcase: xfstests version: xfstests-x86_64-a7df89e-1_20230410 with following parameters: disk: 4HDD fs: xfs test: generic-group-17 compiler: gcc-11 test machine: 4 threads Intel(R) Core(TM) i5-6500 CPU @ 3.20GHz (Skylake) with 32G memory (please refer to attached dmesg/kmsg for entire log/backtrace) If you fix the issue, kindly add following tag | Reported-by: kernel test robot <yujie.liu@intel.com> | Link: https://lore.kernel.org/oe-lkp/202305041600.1633e4ac-yujie.liu@intel.com generic/351 - output mismatch (see /lkp/benchmarks/xfstests/results//generic/351.out.bad) --- tests/generic/351.out 2023-04-10 17:18:19.000000000 +0000 +++ /lkp/benchmarks/xfstests/results//generic/351.out.bad 2023-04-28 03:22:46.227470830 +0000 @@ -25,7 +25,7 @@ Destroy device Create w/o unmap or writesame and format Zero punch, no fallback available -fallocate: Operation not supported +fallocate: No such file or directory Zero range, write fallback Check contents ... (Run 'diff -u /lkp/benchmarks/xfstests/tests/generic/351.out /lkp/benchmarks/xfstests/results//generic/351.out.bad' to see the entire diff) QA output created by 351 Create and format Regular fallocate fallocate: Operation not supported Insert range fallocate: Operation not supported Collapse range fallocate: Operation not supported Unaligned zero range fallocate: Invalid argument Unaligned punch fallocate: Invalid argument Zero range past MAX_LFS_FILESIZE keep size fallocate: File too large Zero range past MAX_LFS_FILESIZE fallocate: File too large Zero range to MAX_LFS_FILESIZE fail w/o keepsize fallocate: Invalid argument Zero range starts past EOD fallocate: Invalid argument Punch starts past EOD fallocate: Invalid argument Check contents b83f9394092e15bdcda585cd8e776dc6 SCSI_DEBUG_DEV Destroy device Create w/o unmap or writesame and format Zero punch, no fallback available fallocate: No such file or directory Zero range, write fallback Check contents 0fc6bc93cd0cd97e3cde5ea39ea1185d SCSI_DEBUG_DEV Destroy device
diff --git a/block/fops.c b/block/fops.c index d2e6be4e3d1c..2fd7e8b9ab48 100644 --- a/block/fops.c +++ b/block/fops.c @@ -648,25 +648,27 @@ static long blkdev_fallocate(struct file *file, int mode, loff_t start, filemap_invalidate_lock(inode->i_mapping); - /* Invalidate the page cache, including dirty pages. */ - error = truncate_bdev_range(bdev, file->f_mode, start, end); - if (error) - goto fail; - + /* + * Invalidate the page cache, including dirty pages, for valid + * de-allocate mode calls to fallocate(). + */ switch (mode) { case FALLOC_FL_ZERO_RANGE: case FALLOC_FL_ZERO_RANGE | FALLOC_FL_KEEP_SIZE: - error = blkdev_issue_zeroout(bdev, start >> SECTOR_SHIFT, + error = truncate_bdev_range(bdev, file->f_mode, start, end) || + blkdev_issue_zeroout(bdev, start >> SECTOR_SHIFT, len >> SECTOR_SHIFT, GFP_KERNEL, BLKDEV_ZERO_NOUNMAP); break; case FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE: - error = blkdev_issue_zeroout(bdev, start >> SECTOR_SHIFT, + error = truncate_bdev_range(bdev, file->f_mode, start, end) || + blkdev_issue_zeroout(bdev, start >> SECTOR_SHIFT, len >> SECTOR_SHIFT, GFP_KERNEL, BLKDEV_ZERO_NOFALLBACK); break; case FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE | FALLOC_FL_NO_HIDE_STALE: - error = blkdev_issue_discard(bdev, start >> SECTOR_SHIFT, + error = truncate_bdev_range(bdev, file->f_mode, start, end) || + blkdev_issue_discard(bdev, start >> SECTOR_SHIFT, len >> SECTOR_SHIFT, GFP_KERNEL); break; default: