Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp10702512rwr; Fri, 12 May 2023 11:38:14 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ50O/UHH+WI0Kc06Kgkg5aOewe0h1GABleWJAWyhlUqlN+e0duHav+pKd5HzJhypM5hzTkP X-Received: by 2002:a17:902:e5c4:b0:1a5:329d:b975 with SMTP id u4-20020a170902e5c400b001a5329db975mr29563082plf.66.1683916694719; Fri, 12 May 2023 11:38:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683916694; cv=none; d=google.com; s=arc-20160816; b=ghjti+t5RlJsg8D4d1cZrmYQh3AIjQWTOH9cTISCxF85KqBxS1ZlG4Gw16r5dNVCmV JVFlSxYSfgwi3EnLCLMq/auOtmFHu8e26AjdUAnuizCMYgxmQgODsKYo+2gszYREY7m2 4gbMDk7kWS+Amue5s2MQbcZgR9G0pOxPycL4/PiM/XTOmuUMObmen6Z99jRakFUarikC JVTQYt1IDJtSFFp8tiBvgU688BBj2mu1vw32GGH8ESXFUO6hiClLolwMP4K1wnJH+rSy eSTCsF/BygH2KZbr/dcGAJEIIXJSzCWo+n4J8Awffo6GMQmL/+HZfy+POBRuzs9WMHCp spaw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=9AcPqQ1elBntnp4bfxi3RPiOgQB3pwN3RVonwkh0x18=; b=pmr6YmCPG6KqL7pjtDCjR/1kKaNBY/6AT++GD39Sz+YZnjqe74vyS4f5xZZ2Q1Fgam W6ZNhQmlo9U28P5gGz8RHmks33TFAq9AbvxfAb32TEO8F4A3d3U0WszWdsx/byqFGKG+ HR3fuI5ARbvofMq3v0DbLsY4VK4rKG34RpVmLAKRq/Pxfk+zeqAX7txm+Wb6ckSesk8h VuMedbUK/wogHxRTLxGGltePSvUFgSm5rin3rZXu9BWqs+vyzCxUcfRQDakSuykNUJKJ YtKx02KHMgZ8DE4ylMdT3ViAIYLnnro5HfwGpV+X3/ntK254vkeSDDUr5nQfE2gBYr6H FG7g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="S3eckV/p"; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l7-20020a17090270c700b0019d038765f6si9148025plt.449.2023.05.12.11.37.57; Fri, 12 May 2023 11:38:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-ext4-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=@kernel.org header.s=k20201202 header.b="S3eckV/p"; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238952AbjELSck (ORCPT + 99 others); Fri, 12 May 2023 14:32:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47786 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238860AbjELScj (ORCPT ); Fri, 12 May 2023 14:32:39 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0F03A1BF4; Fri, 12 May 2023 11:32:07 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 0FC75657B6; Fri, 12 May 2023 18:31:20 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 68219C43443; Fri, 12 May 2023 18:31:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1683916279; bh=QNtq+dSxf9S4yKVS21hk0h0xMTBN4aqiD72KDFJyBk8=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=S3eckV/pl26k1JlgpYv0R7kzza2puVetV/PeBl8/OL+6nvWP/BO5PEXTygIWRKUWV xbSja4rYBbpwOG/7GKAJtle5TcPVb/r7fk8oyYwhys+yS3TyDTWNyhg8hbS5DHI3O/ Rm8hlKJn+y/qS4hJ8aZZsSxe640f32ldjp0qCY1273MnyRul8tDEwL9sF5g9CQZTHo 51DuqmZ/1EaPhWY4C8Rr0p5qdOPHiqMhdKa84V5azCajimUcER8gcTU3ccAbd0ZxLR wvLMS3pAr6k5gpBegrqX6caWeLBajjSiv+obtkeZw48No4aSrsVmEEeZH2AlbtwNkt si0W2yVltrr0g== Date: Fri, 12 May 2023 11:31:18 -0700 From: "Darrick J. Wong" To: Sarthak Kukreti Cc: dm-devel@redhat.com, linux-block@vger.kernel.org, linux-ext4@vger.kernel.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, Jens Axboe , "Michael S. Tsirkin" , Jason Wang , Stefan Hajnoczi , Alasdair Kergon , Mike Snitzer , Christoph Hellwig , Brian Foster , Theodore Ts'o , Andreas Dilger , Bart Van Assche , stable@vger.kernel.org Subject: Re: [PATCH v6 1/5] block: Don't invalidate pagecache for invalid falloc modes Message-ID: <20230512183118.GD858791@frogsfrogsfrogs> References: <20230420004850.297045-1-sarthakkukreti@chromium.org> <20230506062909.74601-1-sarthakkukreti@chromium.org> <20230506062909.74601-2-sarthakkukreti@chromium.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230506062909.74601-2-sarthakkukreti@chromium.org> X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham 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: X-Mailing-List: linux-ext4@vger.kernel.org On Fri, May 05, 2023 at 11:29:05PM -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") > Cc: stable@vger.kernel.org > Reported-by: Darrick J. Wong > Signed-off-by: Sarthak Kukreti Ideally you'd only take filemap_invalidate_lock for valid modes, but eh who cares about efficiency for the EOPNOTSUPP case, let's move on. :) Reviewed-by: Darrick J. Wong --D > --- > block/fops.c | 21 ++++++++++++++++----- > 1 file changed, 16 insertions(+), 5 deletions(-) > > diff --git a/block/fops.c b/block/fops.c > index d2e6be4e3d1c..4c70fdc546e7 100644 > --- a/block/fops.c > +++ b/block/fops.c > @@ -648,24 +648,35 @@ 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 = truncate_bdev_range(bdev, file->f_mode, start, end); > + if (error) > + goto fail; > + > error = 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 = truncate_bdev_range(bdev, file->f_mode, start, end); > + if (error) > + goto fail; > + > error = 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 = truncate_bdev_range(bdev, file->f_mode, start, end); > + if (error) > + goto fail; > + > error = blkdev_issue_discard(bdev, start >> SECTOR_SHIFT, > len >> SECTOR_SHIFT, GFP_KERNEL); > break; > -- > 2.40.1.521.gf1e218fcd8-goog >