From nobody Mon Jun 8 04:25:44 2026 Received: from cstnet.cn (smtp21.cstnet.cn [159.226.251.21]) (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 8B08D340403; Thu, 4 Jun 2026 02:20:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=159.226.251.21 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780539617; cv=none; b=Jy0nBNbQeZU93Jx5mUKytgvn5z8YRYxg0J3mp1kw4OMxfSfH+Fe/QW8QXlqMOZthf0Kc+7TSLConXItFMmblhlD+pq5+eZgPFjoc2KVygXdpOKIcadpo9RGnQ/yAvqOBVlpwzawCpgKGHRj/tNE9Kkd3BbU/HthIlrkj5QZyinc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780539617; c=relaxed/simple; bh=aJWleBx/5Dcu19+quRXRZYQfmXahNHmM0M9vSy1P+vw=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=Mw0GxPVzyJb2Xi6rTimEVyE3v528eIO1nnlFp/3hrJGaCGKTRDuIN31rHB76y8tmTopYanhwbwqDuo2FMqfKPv7O1hmDtcG26pulUAy5WF8+9zpKZa3qZfz5gmBSFLyF0x/A6gOLQhLXwCa0OgSzjCrzsRmskqU4gdQrVpVMiRw= 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.21 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-01 (Coremail) with SMTP id qwCowACnR9DX4CBqcMaQAA--.8961S2; Thu, 04 Jun 2026 10:20:07 +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 v4] ceph: fix writeback_count leak in write_folio_nounlock() Date: Thu, 4 Jun 2026 02:19:51 +0000 Message-Id: <20260604021951.3761714-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: qwCowACnR9DX4CBqcMaQAA--.8961S2 X-Coremail-Antispam: 1UD129KBjvJXoWxJr4UXF4xKw4fKrWDtrW3Awb_yoW8Kry8pr Wjk34DKr40vr1xGr9xCasYq3WYk3y8Cr4fKF4UXF13uFn5Xr42ga4jq3yYqF13AryfJa9a qF4vkrykuayDAFJanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUkK14x267AKxVW8JVW5JwAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2ocxC64kIII0Yj41l84x0c7CEw4AK67xGY2AK02 1l84ACjcxK6xIIjxv20xvE14v26ryj6F1UM28EF7xvwVC0I7IYx2IY6xkF7I0E14v26r4j 6F4UM28EF7xvwVC2z280aVAFwI0_Cr1j6rxdM28EF7xvwVC2z280aVCY1x0267AKxVWxJr 0_GcWle2I262IYc4CY6c8Ij28IcVAaY2xG8wAqx4xG64xvF2IEw4CE5I8CrVC2j2WlYx0E 2Ix0cI8IcVAFwI0_JF0_Jw1lYx0Ex4A2jsIE14v26r4UJVWxJr1lOx8S6xCaFVCjc4AY6r 1j6r4UM4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwCY1x0262kKe7AK xVWUAVWUtwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F4 0E14v26r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_JF0_Jw1l IxkGc2Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVWUJVWUCwCI42IY6xIIjxv20xvEc7CjxV AFwI0_Jr0_Gr1lIxAIcVCF04k26cxKx2IYs7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r1j 6r4UMIIF0xvEx4A2jsIEc7CjxVAFwI0_Jr0_GrUvcSsGvfC2KfnxnUUI43ZEXa7VUbLiSJ UUUUU== X-CM-SenderInfo: pyxotu46lvutnvoduhdfq/1tbiBgoIA2ogubF-3gABsl 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 Reviewed-by: Viacheslav Dubeyko --- Changes in v4: - Also clear write_congested flag when decrementing writeback_count on error paths, as suggested by Viacheslav Dubeyko. - Fix typo error. - Fix diff error --- fs/ceph/addr.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/fs/ceph/addr.c b/fs/ceph/addr.c index 0a86f672cc09..7fab73874068 100644 --- a/fs/ceph/addr.c +++ b/fs/ceph/addr.c @@ -790,6 +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); + 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 @@ -809,6 +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); + 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); } } @@ -847,6 +853,9 @@ static int write_folio_nounlock(struct folio *folio, ceph_vinop(inode), folio); folio_redirty_for_writepage(wbc, folio); folio_end_writeback(folio); + 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