From nobody Mon Jun 8 06:38:14 2026 Received: from cstnet.cn (smtp25.cstnet.cn [159.226.251.25]) (using TLSv1.2 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7E7FA1429D; Wed, 3 Jun 2026 01:25:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=159.226.251.25 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780449919; cv=none; b=CLhg8v4nTyjlKzzqsFXqZhnTNNUq8O7pFJNvS9QGEBq+dyKcQwDIcIjBfrEyMXlYQD+AjVi9xjgqVJPoKytxTTtwyf6CRsIJJxUgrih/eGu4h50qNid+WICpJgjENaq4mdeAUmW4WAkIw9/W4JRbvN1+b6xzqZ2k1bf1ay7JN9M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780449919; c=relaxed/simple; bh=nfUGedCUQfBOXGF/ntq0IvsVNb9oZ6rc9UnAZfSkbU0=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=qpGO9EM3Rzf7OUytx1Du3sMwReKbsy3/O6XpzcdjtFDusqfAX+0khyHSARNKxGY7cp6Wz3XTsMEeDNKmPQTcU+T1ZRDCkPWNWZlH90PDWNxCUDMEdT9gNi7/syTddESNez71OPyjXJeQ0pUaxI72nf5X/8XSLlSKzgj8To0AkIg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=iscas.ac.cn; spf=pass smtp.mailfrom=iscas.ac.cn; arc=none smtp.client-ip=159.226.251.25 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=iscas.ac.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=iscas.ac.cn Received: from dfae2b116770.home.arpa (unknown [36.110.52.2]) by APP-05 (Coremail) with SMTP id zQCowADnU+d4gh9q95E0Eg--.10537S2; Wed, 03 Jun 2026 09:25:12 +0800 (CST) From: Wentao Liang To: idryomov@gmail.com, amarkuze@redhat.com, slava@dubeyko.com Cc: ceph-devel@vger.kernel.org, linux-kernel@vger.kernel.org, Wentao Liang , stable@vger.kernel.org Subject: [PATCH v3] ceph: fix writeback_count leak in write_folio_nounlock() Date: Wed, 3 Jun 2026 01:25:00 +0000 Message-Id: <20260603012500.3688976-1-vulab@iscas.ac.cn> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: zQCowADnU+d4gh9q95E0Eg--.10537S2 X-Coremail-Antispam: 1UD129KBjvJXoWxJr4UXF4xKw4fKrWDtrW3Awb_yoW5JF4rpr Wjk34qkr40vr1xGr98Cas5t3W5C3y8CrWfKF4UJF13uFn5Xr4jgayjq34YqF1fAryfJa9a qr4vkryruayqyFJanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUkE14x267AKxVW8JVW5JwAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2ocxC64kIII0Yj41l84x0c7CEw4AK67xGY2AK02 1l84ACjcxK6xIIjxv20xvE14v26r4j6ryUM28EF7xvwVC0I7IYx2IY6xkF7I0E14v26r4j 6F4UM28EF7xvwVC2z280aVAFwI0_Gr1j6F4UJwA2z4x0Y4vEx4A2jsIEc7CjxVAFwI0_Cr 1j6rxdM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40Ex7xfMcIj 6xIIjxv20xvE14v26r126r1DMcIj6I8E87Iv67AKxVW8Jr0_Cr1UMcvjeVCFs4IE7xkEbV WUJVW8JwACjcxG0xvY0x0EwIxGrwACjI8F5VA0II8E6IAqYI8I648v4I1lc7CjxVAaw2AF wI0_JF0_Jw1l42xK82IYc2Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1lx2IqxVAqx4 xG67AKxVWUJVWUGwC20s026x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r126r1D MIIYrxkI7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_Jr0_JF4lIxAIcVC0I7IYx2IY6xkF7I 0E14v26r1j6r4UMIIF0xvE42xK8VAvwI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxVWU JVW8JwCI42IY6I8E87Iv6xkF7I0E14v26r1j6r4UYxBIdaVFxhVjvjDU0xZFpf9x0JUHpB fUUUUU= X-CM-SenderInfo: pyxotu46lvutnvoduhdfq/1tbiCQ4GA2oe8TlyywABsG Content-Type: text/plain; charset="utf-8" write_folio_nounlock() increments fsc->writeback_count to track in-flight writeback operations. On several error paths where the function returns early (folio lookup failure, snapshot context allocation failure, and writepages submission failure), the function returns without calling atomic_long_dec_return() to decrement the counter. Each leaked increment keeps the counter above zero, which can prevent the filesystem from cleanly unmounting or suspending writes. Add atomic_long_dec_return() calls on all error paths that currently return without decrementing the counter. Fixes: d55207717ded ("ceph: add encryption support to writepage and writepa= ges") Cc: stable@vger.kernel.org Signed-off-by: Wentao Liang --- Changes in v3: - Also clear write_congested flag when decrementing writeback_count on error paths, as suggested by Viacheslav Dubeyko. - Fix typo error. --- fs/ceph/addr.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/fs/ceph/addr.c b/fs/ceph/addr.c index a606378649c3..7fab73874068 100644 --- a/fs/ceph/addr.c +++ b/fs/ceph/addr.c @@ -790,7 +790,9 @@ static int write_folio_nounlock(struct folio *folio, ceph_wbc.truncate_size, true); if (IS_ERR(req)) { folio_redirty_for_writepage(wbc, folio); - atomic_long_dec(&fsc->writeback_count); + if (atomic_long_dec_return(&fsc->writeback_count) < + CONGESTION_OFF_THRESH(fsc->mount_options->congestion_kb)) + fsc->write_congested =3D false; return PTR_ERR(req); } =20 @@ -810,7 +812,9 @@ static int write_folio_nounlock(struct folio *folio, folio_redirty_for_writepage(wbc, folio); folio_end_writeback(folio); ceph_osdc_put_request(req); - atomic_long_dec(&fsc->writeback_count); + if (atomic_long_dec_return(&fsc->writeback_count) < + CONGESTION_OFF_THRESH(fsc->mount_options->congestion_kb)) + fsc->write_congested =3D false; return PTR_ERR(bounce_page); } } @@ -849,7 +853,9 @@ static int write_folio_nounlock(struct folio *folio, ceph_vinop(inode), folio); folio_redirty_for_writepage(wbc, folio); folio_end_writeback(folio); - atomic_long_dec_return(&fsc->writeback_count); + if (atomic_long_dec_return(&fsc->writeback_count) < + CONGESTION_OFF_THRESH(fsc->mount_options->congestion_kb)) + fsc->write_congested =3D false; return err; } if (err =3D=3D -EBLOCKLISTED) --=20 2.34.1