Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp3332209iob; Mon, 16 May 2022 19:42:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyXyc8cWkVmuAHE6t0iBFlj6WfvDPOnDbqq7ODL0HYlJDCvuE0XqfwlTsd8t0kiLPKtAPdo X-Received: by 2002:a17:907:6090:b0:6fa:14ca:fba8 with SMTP id ht16-20020a170907609000b006fa14cafba8mr18032736ejc.212.1652755379498; Mon, 16 May 2022 19:42:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652755379; cv=none; d=google.com; s=arc-20160816; b=DuMwO3pt98N9KQ4zllcz24jcH+94kQJWZRL6i3JNOmYNjyZQ7XYN/DPAd/OXbo+fXo T8o48To1wK1UiNpI1vpc5kn5TlEE8JUAo220AAg+DcIztJm5Vlx2ROT5JgrUzLkBJzTs ifT75nitv0F7dTupFI/D69mirM/Is1cs2tZK76EfK1ms0wVWBTORE5wZzArbJDtYncrI 8G3HVRR1IhzSj3TEqrau1BgZP4x5iBdipPbrN5Y/nWgs3QVEh7mg2rkLPCL2TanNDw2P 5E+N3s4Tj+agVmr5ybS/585+MDh4Jd1uKQGLG8cen5QsPjPs/sHFuzcfzYaACCqv1DFl /AuQ== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=zhZQ1IsSe37dUB7jhnuDp9x8Y2grHbyXVMQR1nTR1mg=; b=y+j45yDLjxpjlo1Vt+sBs76PJNRY/9BvYJZga0Vcq+Fd23N2o+S2MDqG4EUnyAO5d7 inNdbax0khtFqP9BBawA5is1GiUhQqc+ZXQLLF6o3xoAHt3cEyZp0AsNmqIpvjc+yozB sDdQYJ1Ag4Zg1LEMiwRfmHsLwmSW2AVdRmzA3l78WN/azWbIhvoxA+AAEpLHDtP1pYjW zUbDvBkwOT8o7I717eYcQ5N9dP90PvbpKwFn0srYb0Aqk8mGhPvP2aDewhjs1RAIIZo8 APIRj+uvusNuJCgjs8v1nweSxVMI1OwpTB+lT9YW/NtzbAx4Ndk2YA43JsPPyR75/LUK oa3A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=rgKj8meF; 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=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k8-20020a05640212c800b0042ab9211a07si3171439edx.473.2022.05.16.19.42.34; Mon, 16 May 2022 19:42: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=@linuxfoundation.org header.s=korg header.b=rgKj8meF; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347556AbiEPU0V (ORCPT + 99 others); Mon, 16 May 2022 16:26:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48852 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347731AbiEPT6I (ORCPT ); Mon, 16 May 2022 15:58:08 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D4E4E483BB; Mon, 16 May 2022 12:49:47 -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 ams.source.kernel.org (Postfix) with ESMTPS id 7B05FB81612; Mon, 16 May 2022 19:49:46 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id BF329C385AA; Mon, 16 May 2022 19:49:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1652730585; bh=cT2tFWx4y6h1jKST9Xbxf3XHUjKuhrR4MsISZKADkV0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rgKj8meFidk7GIqPThSsOtGJaOp+kDE5BTEDNLzpVdODbMZzxbFw9fyz+ND0gt+e5 iDcs0T6TigRjt5niW/WIpAAqKvA6QRGcjtHP89FjyOUSopblomoqjDPRoB3avrQajM aZP7/XfON4uwPclOx2+KJh6T+AJ+pldqwLCeyxvY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Andreas Gruenbacher , Sasha Levin Subject: [PATCH 5.15 044/102] gfs2: Fix filesystem block deallocation for short writes Date: Mon, 16 May 2022 21:36:18 +0200 Message-Id: <20220516193625.264729898@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220516193623.989270214@linuxfoundation.org> References: <20220516193623.989270214@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,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-kernel@vger.kernel.org From: Andreas Gruenbacher [ Upstream commit d031a8866e709c9d1ee5537a321b6192b4d2dc5b ] When a write cannot be carried out in full, gfs2_iomap_end() releases blocks that have been allocated for this write but haven't been used. To compute the end of the allocation, gfs2_iomap_end() incorrectly rounded the end of the attempted write down to the next block boundary to arrive at the end of the allocation. It would have to round up, but the end of the allocation is also available as iomap->offset + iomap->length, so just use that instead. In addition, use round_up() for computing the start of the unused range. Fixes: 64bc06bb32ee ("gfs2: iomap buffered write support") Signed-off-by: Andreas Gruenbacher Signed-off-by: Sasha Levin --- fs/gfs2/bmap.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/fs/gfs2/bmap.c b/fs/gfs2/bmap.c index fbdb7a30470a..f785af2aa23c 100644 --- a/fs/gfs2/bmap.c +++ b/fs/gfs2/bmap.c @@ -1154,13 +1154,12 @@ static int gfs2_iomap_end(struct inode *inode, loff_t pos, loff_t length, if (length != written && (iomap->flags & IOMAP_F_NEW)) { /* Deallocate blocks that were just allocated. */ - loff_t blockmask = i_blocksize(inode) - 1; - loff_t end = (pos + length) & ~blockmask; + loff_t hstart = round_up(pos + written, i_blocksize(inode)); + loff_t hend = iomap->offset + iomap->length; - pos = (pos + written + blockmask) & ~blockmask; - if (pos < end) { - truncate_pagecache_range(inode, pos, end - 1); - punch_hole(ip, pos, end - pos); + if (hstart < hend) { + truncate_pagecache_range(inode, hstart, hend - 1); + punch_hole(ip, hstart, hend - hstart); } } -- 2.35.1