From patchwork Thu Apr 20 01:47:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sarthak Kukreti X-Patchwork-Id: 85679 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp3097vqo; Wed, 19 Apr 2023 18:52:00 -0700 (PDT) X-Google-Smtp-Source: AKy350bwSuiZedQlJ8bTK52pfED3zQJz05KDOqmfVFJZ3kjcvBssxS+sLXVBex3hCkDJUuKQPng3 X-Received: by 2002:a17:902:e80c:b0:1a8:32e:3256 with SMTP id u12-20020a170902e80c00b001a8032e3256mr7380626plg.35.1681955519906; Wed, 19 Apr 2023 18:51:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681955519; cv=none; d=google.com; s=arc-20160816; b=fVfDj14oOZVoC6AjiQlH6wPI2nukJCjk99SCpgq+ttcZ01BlR2N0ELzgH8bk2ku+mJ dec2AJ7HNXLH0lV9TE+rAoIXWvZ80bqW9I/B39k+uZKAqurA1LcVkv0XMlZJa2QDgHXY e76i1TF29SeKwgcMNFLlwYux7vH0Ffl5GGo5jA1rX2nrxZusgocW1OVJP9oBhkfhT68s HIajQbUPknp/LA4a2mbcMpXZyYQlVuFwnMv8HevPe7m+yeFxaeRJp11f1cYbwtYwLFfi /9he7EgmJMnci/aS/VGfwAxoz19mmYqk1dEieR+bi7N1c3/5ytslozvre7XFzHrZQQnL FpDw== 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=lyurZ/3V3e/TfJ64+oQeFZRXuRpGYngRPpwbALjOBlU=; b=Ym99/RJKpN/z4S5yOWp2O5i2JkckJpqUD9GKhtV0ZHadXTIHey+1DgiGn8l2P+Qw24 I+iCFv7AI6c3tfWicVpptsyUwuS3JXX3fd0jf1syhCRsB9srqbmg0sQYQuzuViBdC4Is YVJR+MSYj/Z/j6nu5p2Z/q45TKyYECWs0KrBJyid+s8+ap9gJCiThV7RhS2lTcYnlHET Kb4gSzSNpx7dCsnvSKOrdO/qpyy4q6WAa8gcaWjHGCEh4Cemt76UAWelC6cFW1hmZfRI NZd62hA3MJJq7cr6vnOSyBw11jeMbMb7uNwiYVgcaTCgIr07cvXUbtV/W4guHO1Cpo7+ RaXA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=OCgRfiXC; 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 q12-20020a170902c9cc00b001a661053de9si344978pld.293.2023.04.19.18.51.23; Wed, 19 Apr 2023 18:51:59 -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=OCgRfiXC; 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 S231860AbjDTBrz (ORCPT + 99 others); Wed, 19 Apr 2023 21:47:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48590 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229547AbjDTBrw (ORCPT ); Wed, 19 Apr 2023 21:47:52 -0400 Received: from mail-pf1-x42e.google.com (mail-pf1-x42e.google.com [IPv6:2607:f8b0:4864:20::42e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 146961FD0 for ; Wed, 19 Apr 2023 18:47:39 -0700 (PDT) Received: by mail-pf1-x42e.google.com with SMTP id d2e1a72fcca58-63b4a64c72bso471165b3a.0 for ; Wed, 19 Apr 2023 18:47:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1681955258; x=1684547258; 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=lyurZ/3V3e/TfJ64+oQeFZRXuRpGYngRPpwbALjOBlU=; b=OCgRfiXCuStjsazsK/NTRG8oGDsxx2kymbqOUtb5DkGOo4AaKoAVfks39i/pw3VtlW HpuCWlh+CByxmIJ1yPC8mnj0TEsEbjqKGq34F7DWBd1qrLUQEDifZ5lUmgOXKP6GrnNy Mdb+rAAbOF5E5UOc9S1Z3pCK9q/A1P2p4iX2c= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681955258; x=1684547258; 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=lyurZ/3V3e/TfJ64+oQeFZRXuRpGYngRPpwbALjOBlU=; b=Bk7qer5NZ4FPFO25bC2pMN9d+2fYG4SanwogQw2BADYtCfjBheVhCsUbAO8mi75Y6x TdBna7oOGAygj8v7D7UyEtY5+INKJClULMP0A6k7KkBv58CY9646dBv0V1buKvWaulKM ACDoiJNBLK4z5BHsso/Z5SeUx3g6QBkuj799yUUiUqPPNuYyCbfdnqp4fvH8kpwrPf3r wsQYvSn1R8glA0hqbad2nB+5N9PD4udX9f69ES4hDFtEgIiMh3PhqOSTMaEMpEcOlo/x ypa2ED5zGWmEy9B1gKZV8Xkmkh5e9JmCPVyIxqeQLV7JXCYbDIWYlA/FItONXn+1DJ6N ebmw== X-Gm-Message-State: AAQBX9ed2Cfm6SdmFf4IPKymYylIUuQ6mNnsc97uhI6E+mnEBAchUbIX 5bmWlUnLLGKK7sxLW0HOkZ+fAg== X-Received: by 2002:a05:6a00:1489:b0:63d:3aed:44fb with SMTP id v9-20020a056a00148900b0063d3aed44fbmr6882651pfu.21.1681955258324; Wed, 19 Apr 2023 18:47:38 -0700 (PDT) Received: from sarthakkukreti-glaptop.hsd1.ca.comcast.net ([2601:647:4200:b5b0:402e:4c2e:4e90:d79d]) by smtp.gmail.com with ESMTPSA id y4-20020a62ce04000000b006363690dddasm60753pfg.5.2023.04.19.18.47.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Apr 2023 18:47:37 -0700 (PDT) From: Sarthak Kukreti 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 , "Michael S. Tsirkin" , Jason Wang , Stefan Hajnoczi , Alasdair Kergon , Mike Snitzer , Christoph Hellwig , Brian Foster , Theodore Ts'o , Andreas Dilger , Bart Van Assche , Daniil Lunev , "Darrick J. Wong" Subject: [PATCH v5-fix 1/5] block: Don't invalidate pagecache for invalid falloc modes Date: Wed, 19 Apr 2023 18:47:34 -0700 Message-ID: <20230420014734.302304-1-sarthakkukreti@chromium.org> X-Mailer: git-send-email 2.40.0.634.g4ca3ef3211-goog In-Reply-To: <20230420004850.297045-2-sarthakkukreti@chromium.org> References: <20230420004850.297045-2-sarthakkukreti@chromium.org> MIME-Version: 1.0 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: 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?1763658190915609039?= 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 Reported-by: Darrick J. Wong --- block/fops.c | 37 ++++++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/block/fops.c b/block/fops.c index d2e6be4e3d1c..d359254c645d 100644 --- a/block/fops.c +++ b/block/fops.c @@ -648,26 +648,37 @@ 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, - len >> SECTOR_SHIFT, GFP_KERNEL, - BLKDEV_ZERO_NOUNMAP); + error = truncate_bdev_range(bdev, file->f_mode, start, end); + if (!error) + 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 = blkdev_issue_zeroout(bdev, start >> SECTOR_SHIFT, - len >> SECTOR_SHIFT, GFP_KERNEL, - BLKDEV_ZERO_NOFALLBACK); + error = truncate_bdev_range(bdev, file->f_mode, start, end); + if (!error) + 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 = blkdev_issue_discard(bdev, start >> SECTOR_SHIFT, - len >> SECTOR_SHIFT, GFP_KERNEL); + error = truncate_bdev_range(bdev, file->f_mode, start, end); + if (!error) + error = blkdev_issue_discard(bdev, + start >> SECTOR_SHIFT, + len >> SECTOR_SHIFT, + GFP_KERNEL); break; default: error = -EOPNOTSUPP;