Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp3755058rdg; Wed, 18 Oct 2023 05:22:29 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEcSIphKQLNECVMhmUr+iH0i9Aj6uOv1ly/p6uEXW1NM9NblXb3ek11t/u1pGhWi9Mga3Yx X-Received: by 2002:a05:6a21:999f:b0:17b:129b:196f with SMTP id ve31-20020a056a21999f00b0017b129b196fmr4104989pzb.11.1697631749310; Wed, 18 Oct 2023 05:22:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697631749; cv=none; d=google.com; s=arc-20160816; b=cFourFsOVXqKV1Wg/it2CGG0fIn2cuByPwoV6vF/3noQeocVoPV2aJM2oMdL4HEnqh L094d/lr8a+HcSU2wzo40+QJ+GcEysfYJUQu1t4kA4eMqp92DRqknhayDScWpa9Z3woZ lG3YKRIOS8JeRubahx7Mtk/LrHa9WqdF1+aZ9jTqqv/FvcEag6IE/sPvY22UxgqMM8hZ 7vHsNxqe4fkwr/o8U1/DIsk+iyJ/pjHeHwCzzGaveZKWfp66tecs97samb7xia4bSWyl vQhvu1doXYtYzJ3VoqHljdLtY91CWLL3kpancU6tKHp5SPxPbA9VyRfwRzGB54ef6cUy c0XQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=gI41HEG/MX0FGVn2DGG5vTKRieE/C50AoSmPuZZoivE=; fh=TpYwbpu0Q0tCFZwnNQUHT61l4404hedGmHVjM2fx16U=; b=c0V6niaDz9/6VqH4sCGfOgy5RaYMkRD/h5b0SP/vjhA5YekgoiaGHzsSGSnY5P5Q/h 6v2Y9TJvf0fNnHL9vc4ysx+8hmSKiGnTS03os0yAUcmDE/6lhRMa8YK9+wMaLsV+aLTG FYoSR1NFEAkTQBur1qbaI4CKMcGkL4D/Ya/6Z0ETHXG0z+8N7eT/9/pgrIIzoUQT69rZ IEz49XhXS2/wpJEWzLlMR36tn+ALtO37PVIwqtbdFXreoBpLUGHRbQJjolat4b8/QRc6 QsM6ET/OVQnjcRVx6dn290wh16PVxtD1KLBLjQIxDEDHafvs27baa3DnCssUqIpH+mTW RqLw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id c10-20020a170902d48a00b001b3fb1742e4si3059196plg.547.2023.10.18.05.22.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Oct 2023 05:22:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 572DE80C246A; Wed, 18 Oct 2023 05:22:28 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229929AbjJRMW0 (ORCPT + 99 others); Wed, 18 Oct 2023 08:22:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47340 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229441AbjJRMWZ (ORCPT ); Wed, 18 Oct 2023 08:22:25 -0400 Received: from verein.lst.de (verein.lst.de [213.95.11.211]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8AB5198; Wed, 18 Oct 2023 05:22:23 -0700 (PDT) Received: by verein.lst.de (Postfix, from userid 2407) id 56BE467373; Wed, 18 Oct 2023 14:22:20 +0200 (CEST) Date: Wed, 18 Oct 2023 14:22:20 +0200 From: Christoph Hellwig To: Jan Stancek Cc: djwong@kernel.org, willy@infradead.org, hch@lst.de, linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, viro@zeniv.linux.org.uk Subject: Re: [PATCH] iomap: fix short copy in iomap_write_iter() Message-ID: <20231018122220.GB10751@lst.de> References: <8762e91a210f4cc5713fce05fe5906c18513bd0a.1697617238.git.jstancek@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <8762e91a210f4cc5713fce05fe5906c18513bd0a.1697617238.git.jstancek@redhat.com> User-Agent: Mutt/1.5.17 (2007-11-01) X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS 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-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Wed, 18 Oct 2023 05:22:28 -0700 (PDT) On Wed, Oct 18, 2023 at 10:24:20AM +0200, Jan Stancek wrote: > Make next iteration retry with amount of bytes we managed to copy. The observation and logic fix look good. But I wonder if simply using a goto instead of the extra variable would be a tad cleaner? Something like this? --- diff --git a/fs/iomap/buffered-io.c b/fs/iomap/buffered-io.c index 061f3d14c12001..2d491590795aa4 100644 --- a/fs/iomap/buffered-io.c +++ b/fs/iomap/buffered-io.c @@ -881,8 +881,10 @@ static loff_t iomap_write_iter(struct iomap_iter *iter, struct iov_iter *i) size_t bytes; /* Bytes to write to folio */ size_t copied; /* Bytes copied from user */ + bytes = iov_iter_count(i); +retry: offset = pos & (chunk - 1); - bytes = min(chunk - offset, iov_iter_count(i)); + bytes = min(chunk - offset, bytes); status = balance_dirty_pages_ratelimited_flags(mapping, bdp_flags); if (unlikely(status)) @@ -933,10 +935,12 @@ static loff_t iomap_write_iter(struct iomap_iter *iter, struct iov_iter *i) * halfway through, might be a race with munmap, * might be severe memory pressure. */ - if (copied) - bytes = copied; if (chunk > PAGE_SIZE) chunk /= 2; + if (copied) { + bytes = copied; + goto retry; + } } else { pos += status; written += status;