From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 404B1442FD5; Thu, 30 Jul 2026 14:35:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785422159; cv=none; b=hoT/4ZTliIvWdj3eOIpDNxi/EUzWRgi7AWNymot55aKb43uRL3Kb4BK2j+n81CZQ81a20J7YAeVGYIWgneOmLjnxWHiV0Vu2OMGcZcM/bsy6XxY5If8hXuZ8dJ5MwiknXTBBHgJdKHJ/ywzNNaB9wHn7j7mEgCvvh0+ENZtDi5A= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785422159; c=relaxed/simple; bh=tBv43TTzVQn0Ef8r7cFPs76w0mSTS0FQxbWL4k039jU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=oKjusfZ1HBhje/CUoeEqVMXyA+j7LtiyHS0UNyG8w/qJN8KV1UC1q/8imqjMZcSHLd9NIqhD9BiGk+FxG4EqVLT9tdutI3yWKHRCu5gTfOH7IuJQ4AgDRcNiUpatAeASfVqjiL5oPXSRpyoKoQv36i1XTh1DeAPJHSvtEK+54y4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=lc6ojJkx; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="lc6ojJkx" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8F5251F00A3A; Thu, 30 Jul 2026 14:35:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1785422157; bh=F2iKlwdRsGp1ULtfX7XQhTYafbh0ah+kxbN5YyOvx0Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=lc6ojJkxZUbZEEsbqUG4l72BGgq/VnmewNPll/r2YqIOLnOasc9sj0A3/TwTvdJW5 xrUlormOPf7Y6sZ3ABUp8+Qj3XJkByO7s9CJ3rcb5EmSsEiOtr5BUcX3kSA6JyAWfW hwfzsEV4QyI03eKxz93/jblw3X+5ly3XtbU7xuu8= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Zhang Yi , Joanne Koong , "Darrick J. Wong" , Christoph Hellwig , "Christian Brauner (Amutable)" , Sasha Levin Subject: [PATCH 7.1 317/744] iomap: correct the range of a partial dirty clear Date: Thu, 30 Jul 2026 16:09:50 +0200 Message-ID: <20260730141451.022367508@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260730141444.267951807@linuxfoundation.org> References: <20260730141444.267951807@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 7.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Zhang Yi [ Upstream commit 88c26515313169806a412a362b32a1eca53d21bd ] The block range calculation in ifs_clear_range_dirty() is incorrect when partially clearing a range in a folio. We cannot clear the dirty bit of the first block or the last block if the start or end offset is not blocksize-aligned. This has not yet caused any issues since we always clear a whole folio in iomap_writeback_folio(). Fix this by rounding up the first block to blocksize alignment, and calculate the last block by rounding down (using truncation). Correct the nr_blks calculation accordingly. Fixes: 4ce02c679722 ("iomap: Add per-block dirty state tracking to improve performance") Signed-off-by: Zhang Yi Link: https://patch.msgid.link/20260714082325.325163-2-yi.zhang@huaweicloud.com Reviewed-by: Joanne Koong Reviewed-by: "Darrick J. Wong" Reviewed-by: Christoph Hellwig Signed-off-by: Christian Brauner (Amutable) Signed-off-by: Sasha Levin --- fs/iomap/buffered-io.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/fs/iomap/buffered-io.c b/fs/iomap/buffered-io.c index 5fa9a2c7e30eb8..116110628994df 100644 --- a/fs/iomap/buffered-io.c +++ b/fs/iomap/buffered-io.c @@ -176,13 +176,17 @@ static void ifs_clear_range_dirty(struct folio *folio, { struct inode *inode = folio->mapping->host; unsigned int blks_per_folio = i_blocks_per_folio(inode, folio); - unsigned int first_blk = (off >> inode->i_blkbits); - unsigned int last_blk = (off + len - 1) >> inode->i_blkbits; - unsigned int nr_blks = last_blk - first_blk + 1; + unsigned int first_blk = round_up(off, i_blocksize(inode)) >> + inode->i_blkbits; + unsigned int last_blk = (off + len) >> inode->i_blkbits; unsigned long flags; + if (first_blk >= last_blk) + return; + spin_lock_irqsave(&ifs->state_lock, flags); - bitmap_clear(ifs->state, first_blk + blks_per_folio, nr_blks); + bitmap_clear(ifs->state, first_blk + blks_per_folio, + last_blk - first_blk); spin_unlock_irqrestore(&ifs->state_lock, flags); } -- 2.53.0