From patchwork Thu Apr 20 17:28:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sarthak Kukreti X-Patchwork-Id: 85982 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp505433vqo; Thu, 20 Apr 2023 10:37:03 -0700 (PDT) X-Google-Smtp-Source: AKy350Z7tjOIKK/FmMcCeYHRm4YI3Ax3DSPv5tueZSY+6WTjb8QlSoSyrsYpC+fKXG7Lr497K57G X-Received: by 2002:a17:902:e2c2:b0:1a6:d2a9:3fb7 with SMTP id l2-20020a170902e2c200b001a6d2a93fb7mr2191452plc.40.1682012222866; Thu, 20 Apr 2023 10:37:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682012222; cv=none; d=google.com; s=arc-20160816; b=YEFaBbkD+QMVevKEQdjW/w4ims5AQXB1lf7DgRGN456hqnuM59QzwEujfGX3xtIVNt fcRLQ4UIN6t0VfCdq1Kwzjt1zq/uz5c2nmU3AYavJWVFRIT38fA8wW9wnknEiCw5mSBA CVu2u5nYhRdAph9tcK+af0CeGfMDMdwdR2WD6lmZ+to0maIpAAUNXgUi6BlReEnZ12PG 4ZcB0TVSnx7cMERkn9gFZdLLCEroswK+J0LigeGnOLb2gnEnqEijGmp7nC5ZqwIzJfJw Mccfbn1pXic9J3E3W/FonCkMD1Se5XufbnvSDBRzrusCKBB1dbikhPELyxnUNcKCzVvJ Hk5A== 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=3x8N7sxsFvg5b0uwbahj+PwbPcqRN9aSzyeMa7PrIzY=; b=zRhKW6vbUBXvZsmgU96JQmMSExSk3z6I8p/kpB/lI7p+pBu09Omlr5ZM0qJqdnpsj7 Lu+cEpToSQ4uUa2y3MVkHvuOom5V46Z6tLCpei+bYVFWl2LeBb0+TK5l9sAOSRlziLMi wTwaQU7HzFEQlHOnxEK1bDfsjD033488uR5hoekKtaoFVnWhvExMVm/rfOOa2yWfQviX /quwgx0l+FdBndT0/zlPwS8SznsaW0BE02UPdJVlfOHkEYv+bK5bnb2V7hokwi6807P/ Xnixbd+QbyaKHVOCS46YU3EplYbTFB2duUuesC0h6YsytlJa4uM1WJIPMoxcY0u+jcwz utzA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=PInXabSK; 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 o5-20020a17090ac70500b0024b5a028e7asi767986pjt.47.2023.04.20.10.36.49; Thu, 20 Apr 2023 10:37:02 -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=PInXabSK; 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 S230495AbjDTR2c (ORCPT + 99 others); Thu, 20 Apr 2023 13:28:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34432 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231365AbjDTR23 (ORCPT ); Thu, 20 Apr 2023 13:28:29 -0400 Received: from mail-pf1-x432.google.com (mail-pf1-x432.google.com [IPv6:2607:f8b0:4864:20::432]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 57E2C49ED for ; Thu, 20 Apr 2023 10:28:21 -0700 (PDT) Received: by mail-pf1-x432.google.com with SMTP id d2e1a72fcca58-63b70f0b320so1755694b3a.1 for ; Thu, 20 Apr 2023 10:28:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1682011701; x=1684603701; 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=3x8N7sxsFvg5b0uwbahj+PwbPcqRN9aSzyeMa7PrIzY=; b=PInXabSKPMPkpHkuZFbSfZyAVvTSjLv36Kr/cvSO8TjzWJ6vlXl0FTCM4HkL4ZD4vw aQGfOydJeFSTT7e0EsizobBwWZQwg9OQ166TMTtcAizTmIwmi1rXZ701QcJfeofeXRlS 9cUaCm4t2WOGkiOxpO7Yj6DFl8oRlg4ewN0fo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682011701; x=1684603701; 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=3x8N7sxsFvg5b0uwbahj+PwbPcqRN9aSzyeMa7PrIzY=; b=Jwm/ajsFUe8JbtMAZW18FmHHPzenA0NVH/w26NlhQHGvUdQ1gOE0yaXiREAiDUZ6dl RvHzCXs9LHxsJHYB1JQY4YOvz/nDkGgDK6Tuux7Fn2mVEMavJFqOE2XmTlC4F0h2yhYF 50c3JKWsfPkkXesJL69q+bXnNvCnDN4ZKnFlLvhb8cA74yqnjL3UAyRy1RK7P8zlq8RQ DJiRX0UPhnh7nx8x6iP2E67z3HHnH7zdJq/PVc/Yi0jpW1HF9Pi5LiJLxos4zunePlf3 CuDzsr4CKosCdbg7etgDV0a8Y7LCPpFxqDBeHA2Z1O+f63/zqSbJwS5b9nEv8k1aaHYe mmDg== X-Gm-Message-State: AAQBX9edpdq9DUzg4vYXzSAOzn70+y9eDISzpU0BlWlC4fyko8ctewBe 7VMNnWGAlNwpS3yT2ECj49WsoQ== X-Received: by 2002:a05:6a20:d38d:b0:f0:558b:8fbb with SMTP id iq13-20020a056a20d38d00b000f0558b8fbbmr2889057pzb.34.1682011700784; Thu, 20 Apr 2023 10:28:20 -0700 (PDT) Received: from sarthakkukreti-glaptop.hsd1.ca.comcast.net ([2601:647:4200:b5b0:42d9:debc:8d41:e6c4]) by smtp.gmail.com with ESMTPSA id t9-20020a6549c9000000b0051b3ef1295csm1360372pgs.53.2023.04.20.10.28.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Apr 2023 10:28:20 -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" , stable@vger.kernel.org Subject: [PATCH v5-fix 1/5] block: Don't invalidate pagecache for invalid falloc modes Date: Thu, 20 Apr 2023 10:28:07 -0700 Message-ID: <20230420172807.323150-1-sarthakkukreti@chromium.org> X-Mailer: git-send-email 2.40.0.396.gfff15efe05-goog In-Reply-To: References: 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?1763717648568308989?= 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 --- block/fops.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/block/fops.c b/block/fops.c index d2e6be4e3d1c..20b1eddcbe25 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;