From mboxrd@z Thu Jan 1 00:00:00 1970 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 us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C02C6C77B7A for ; Fri, 19 May 2023 15:17:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1684509460; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=v4lPG5G4QVcg2FmHan7U5qAsyiQKjNieKxhllAs/T2I=; b=U30Ou4SHDHK4sP9/uSxd4q2NCmiF+0OijN3afYSTX6ivaNkizON8MAWCotD1BENXRbciyz aYZxlA/wLJsVv0XtXcHM3zPbpPW90sLdMlXYjsSb1bHUsBo4zoHRCOpMbbTlAjwVfQ8c9J ChbfCYgkY3KSOEh6jAMp/RGAMDFaFwc= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-643-ucUSjEdVNNaIjBcVMzZwQg-1; Fri, 19 May 2023 11:17:37 -0400 X-MC-Unique: ucUSjEdVNNaIjBcVMzZwQg-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 89D71101A52C; Fri, 19 May 2023 15:17:35 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 36EB32026D49; Fri, 19 May 2023 15:17:35 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id E421719465B2; Fri, 19 May 2023 15:17:34 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 0ABA819465A4 for ; Fri, 19 May 2023 15:17:33 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id C5D231121315; Fri, 19 May 2023 15:17:33 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast01.extmail.prod.ext.rdu2.redhat.com [10.11.55.17]) by smtp.corp.redhat.com (Postfix) with ESMTPS id BE9721121314 for ; Fri, 19 May 2023 15:17:33 +0000 (UTC) Received: from us-smtp-inbound-1.mimecast.com (us-smtp-2.mimecast.com [205.139.110.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 997C5858F1C for ; Fri, 19 May 2023 15:17:33 +0000 (UTC) Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-622-BilOl3CIOKSch0I_195u_w-1; Fri, 19 May 2023 11:17:30 -0400 X-MC-Unique: BilOl3CIOKSch0I_195u_w-1 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 EDFAF6558D; Fri, 19 May 2023 15:17:28 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 510EBC433D2; Fri, 19 May 2023 15:17:28 +0000 (UTC) Date: Fri, 19 May 2023 08:17:27 -0700 From: "Darrick J. Wong" To: Sarthak Kukreti Message-ID: <20230519151727.GD11642@frogsfrogsfrogs> References: <20230518223326.18744-1-sarthakkukreti@chromium.org> <20230518223326.18744-2-sarthakkukreti@chromium.org> MIME-Version: 1.0 In-Reply-To: <20230518223326.18744-2-sarthakkukreti@chromium.org> X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 Subject: Re: [dm-devel] [PATCH v7 1/5] block: Don't invalidate pagecache for invalid falloc modes X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: device-mapper development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jens Axboe , Christoph Hellwig , Theodore Ts'o , "Michael S. Tsirkin" , Jason Wang , Bart Van Assche , Mike Snitzer , linux-kernel@vger.kernel.org, stable@vger.kernel.org, linux-block@vger.kernel.org, dm-devel@redhat.com, Andreas Dilger , Stefan Hajnoczi , linux-fsdevel@vger.kernel.org, linux-ext4@vger.kernel.org, Brian Foster , Alasdair Kergon Errors-To: dm-devel-bounces@redhat.com Sender: "dm-devel" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: kernel.org Content-Disposition: inline Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit On Thu, May 18, 2023 at 03:33:22PM -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 Thanks for fixing this, 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.698.g37aff9b760-goog > -- dm-devel mailing list dm-devel@redhat.com https://listman.redhat.com/mailman/listinfo/dm-devel From mboxrd@z Thu Jan 1 00:00:00 1970 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 33BE7C7EE26 for ; Fri, 19 May 2023 15:17:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232289AbjESPRb (ORCPT ); Fri, 19 May 2023 11:17:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48780 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229532AbjESPRa (ORCPT ); Fri, 19 May 2023 11:17:30 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5D000CF; Fri, 19 May 2023 08:17:29 -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 EDD9C61D3F; Fri, 19 May 2023 15:17:28 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 510EBC433D2; Fri, 19 May 2023 15:17:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1684509448; bh=47KTQ+HxzwYC6TsbUYOQ6aOmK4jjWb0xI6ebbOh8XlY=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=eBoUzUHnDSgsYrzw4so+d/v46+i/P/j4IUxwDsjTYBdtazJ9gFSlAlsy35dOA5dAB 98fZ0hSNCK8E3Ff/VyQXKQQ3x9hFwiD2w4hM2rYENyWeXPhVkugepOyzLnDFBB8/4H 51nzDK1yxzVdxXU3YJHR5VQXEaPxtVRp5EvpcQmfKDCue9AB+ShL0CvP1iDdSpglh6 MWmF7J8rXBCAZpQQkpn7BgBq+HJMv7Fp//dscLwf5L6VeL4ftPDmRESHT3py5aPQBA 83lsfrl7iLOXfgQUZ201RO+WG5WlYpLgr3CrPJjOST6Yxp0lgO7nkcDAd11UtSuqfi qklM9iSrUgaOQ== Date: Fri, 19 May 2023 08:17:27 -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 v7 1/5] block: Don't invalidate pagecache for invalid falloc modes Message-ID: <20230519151727.GD11642@frogsfrogsfrogs> References: <20230518223326.18744-1-sarthakkukreti@chromium.org> <20230518223326.18744-2-sarthakkukreti@chromium.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230518223326.18744-2-sarthakkukreti@chromium.org> Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org On Thu, May 18, 2023 at 03:33:22PM -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 Thanks for fixing this, 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.698.g37aff9b760-goog >