Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp4473970rwd; Sun, 11 Jun 2023 08:12:23 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5u7PYshxfCtJO4v8P0eNdB5CMIU7P6Zoyr99hs0raPf7MSl/+RUoa/eHP1s59JkgT6WjgE X-Received: by 2002:a17:90a:190d:b0:258:9995:91cb with SMTP id 13-20020a17090a190d00b00258999591cbmr5808310pjg.49.1686496342569; Sun, 11 Jun 2023 08:12:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686496342; cv=none; d=google.com; s=arc-20160816; b=n5pZJv4V+MPeVCJATnsfJZ6Gq0E6nGhhTFGtm+p9E/6+meFwTE1+4VF2ow1J1ZKv1+ 0CeLGkK19sfatdPRV7tNnWnw9VxRoEnoup8yAx+saG2fEC3SbVX6Eipy3EVcP0QRqcGC ZCv5B6vVA7FRjFaSmRHHWyqRyvueZTaxqAvZWYJVXus4vZQwzx2uI9NEIuNjLHqcLY/N RZqYUGnHbr8jKa3l5dTgIud/rKuV7ymNdfrjHqTu7JVAu2A1Gln1yOKD4d6wLcsiqRTX xYMCAgNoir5MvAlAmIGuDxeCmVjgfnxAwPvkuFRyTQruySK8yARyEHuuxGmyg789snpW AAMg== 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=fDLmQabXCTXwFAPTqybFPxD8zjt2Tccvqs7T+QWFUGI=; b=D5pSOnhEnl6lJIiUnRWL6rU8vTTJ+BwsV2GbYJd4V38idyaEBDxiYNtl0a3mPCm1TB SN7b2ghYy0VLVmSJ9uCMDEDm5NkMe/fsu+G6e/I/raLzxaYFGHSsmbQLS2E/ok1fwzon Uo+bm658KDXTGmd25d3zT/BesQDQ9pBBQ66OkxaAUe8MHSG4i3q7NtDwYZbAVfGBPr+z ufQfBhK6SItMn6zpAovOBQLVf+wtUeru9K/nYVq2QN0pj1zgVf1QDoTIBoNzCAUYQkBM 5aYdKVmtdBUiQyHylgipZR23sSBXrP3+STE0LoNvgP1hPpu22ZiBLVGIEMqx5dCrsRwe QQhA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=h3tqF5j5; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t1-20020a17090aba8100b0025359a570fesi2009320pjr.19.2023.06.11.08.12.02; Sun, 11 Jun 2023 08:12:22 -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=@infradead.org header.s=casper.20170209 header.b=h3tqF5j5; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233618AbjFKOQE (ORCPT + 99 others); Sun, 11 Jun 2023 10:16:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41974 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230233AbjFKOQD (ORCPT ); Sun, 11 Jun 2023 10:16:03 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6CF2CD7; Sun, 11 Jun 2023 07:15:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=fDLmQabXCTXwFAPTqybFPxD8zjt2Tccvqs7T+QWFUGI=; b=h3tqF5j57PCYLSG6yCWfbEfr32 CO4Bz3Z4WqNMAc9oJyokcDxBXOKCP1aZzD1iVbbft4MJyTuKqOt6NOaUDPtKzn5AGyfUEzbAY3Hb9 2QsfVfs1n1rZ304XGiwefNmWKudg0g08CmPkrIV3tQ0l7AED2DYDAFwZHemjsPonI7CqfSuTIZk8V Dz4A19AqgsvjcuIamqN6a0X2Ene3C74V2tHCTiqk8+rUmDi7LAA8UPJSiAz5pmvd8hG8bC7OLFC8L gkEn6q0c/9cwh6moplb+NrTk+T94O8YBgTkp8otJFSUSxd/Ha0JCFQGO5ZITHm1gkppFYcrJnPVLl C40WwV4Q==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1q8LrG-001RLt-8u; Sun, 11 Jun 2023 14:15:54 +0000 Date: Sun, 11 Jun 2023 15:15:54 +0100 From: Matthew Wilcox To: Theodore Ts'o Cc: "Ritesh Harjani (IBM)" , linux-ext4@vger.kernel.org, linux-fsdevel@vger.kernel.org, Ojaswin Mujoo , Disha Goel Subject: Re: [RFCv2 2/5] ext4: Remove PAGE_SIZE assumption of folio from mpage_submit_folio Message-ID: References: <74182f5607ccfc3b1e7f08737fcb3442b42a2124.1684122756.git.ritesh.list@gmail.com> <20230611055831.GF1436857@mit.edu> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230611055831.GF1436857@mit.edu> X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE,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 Sun, Jun 11, 2023 at 01:58:31AM -0400, Theodore Ts'o wrote: > On Mon, May 15, 2023 at 04:10:41PM +0530, Ritesh Harjani (IBM) wrote: > > mpage_submit_folio() was converted to take folio. Even though > > folio_size() in ext4 as of now is PAGE_SIZE, but it's better to > > remove that assumption which I am assuming is a missed left over from > > patch[1]. > > > > [1]: https://lore.kernel.org/linux-ext4/20230324180129.1220691-7-willy@infradead.org/ > > > > Signed-off-by: Ritesh Harjani (IBM) > > I didn't notice this right away, because the failure is not 100% > reliable, but this commit will sometimes cause "kvm-xfstests -c > ext4/encrypt generic/068" to crash. Reverting the patch fixes the > problem, so I plan to drop this patch from my tree. Hrm. Well, let's think about how this can go wrong: @@ -1885,7 +1885,7 @@ static int mpage_submit_folio(struct mpage_da_data *mpd, +struct folio *folio) len = folio_size(folio); if (folio_pos(folio) + len > size && !ext4_verity_in_progress(mpd->inode)) - len = size & ~PAGE_MASK; + len = size - folio_pos(folio); err = ext4_bio_write_folio(&mpd->io_submit, folio, len); if (!err) mpd->wbc->nr_to_write--; Just off-camera is: size = i_size_read(mpd->inode); Now, nothing is preventing i_size to be truncated to far below this folio, right? So if that happened before this patch, we'd write some randomly sized fragment of the page. Now we'll get a negative result ... which is assigned to size_t, so is exabytes in size. So do we care if we write a random fragment of a page after a truncate? If so, we should add: if (folio_pos(folio) >= size) return 0; /* Do we need to account nr_to_write? */ If we simply don't care that we're doing a spurious write, then we can do something like: - len = size & ~PAGE_MASK; + len = size & (len - 1);