From nobody Sat Feb 7 08:42:45 2026 Received: from mail-dl1-f65.google.com (mail-dl1-f65.google.com [74.125.82.65]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 355C52D46D9 for ; Mon, 26 Jan 2026 02:31:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.65 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769394674; cv=none; b=cTZCnn8+kpx6POWfpVvPBVedGius3cx4Y3+fE6WRNECRTyYx4Srkdl/DnfzfbIEEGibXzCZlgalUxpzHbRErDovZo2RLaTRU99oBIUMtIRSTKs0eNdNOcr3XeVpMilZQAh5O0hFHern+4nHG3sZzax0nbd9x108xEbIjVK+i+Cg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769394674; c=relaxed/simple; bh=LEM4dAMdc0CIh1pUicq2+gOIh05/dvfUnzW1HBv6u1c=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=F38QktESqVCLWYnkkCT+LOQJ/O0qHYuQDkXq2/oB5cDOsVsVAWtv+WYuJxKBnfjE8ZSC00VDi6tp1/XXqBry1nhyWD/PaOX56aJJP8pmG8pakt64eDxHOtcXz9Hjnu1/oon7zYpeKMpLI8yeet6LV1/XOubydrKKeb8Jw/r4DYE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=JM9sa9O/; arc=none smtp.client-ip=74.125.82.65 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="JM9sa9O/" Received: by mail-dl1-f65.google.com with SMTP id a92af1059eb24-1248d27f293so2367707c88.0 for ; Sun, 25 Jan 2026 18:31:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1769394672; x=1769999472; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ymnLBLi8khxZIsCQL9bJnfvhV+yX6mpInM8DP2CqmnI=; b=JM9sa9O/2Tjk3oFtofm64g2or4VsGlgB8RCbWr8ZfzTdEaAIE8xguDRdBfbtt8R81g FPKJ6BNrE7NYz1aGQb1S+hyAuPhrI2L9rQp9k3eN0SahWodcB00MOvn/065Ec+5kSjRw LVoRiYBO3hTY6gbYBYpxcmQZxmSThR08aQEIvivhCsvoF0J45P3JQXlTr1Bfg5FLmYMJ xagCoAyLTDE5dJArR8j67EoBe0YqrHzmwrcLBc+SxaL4iwxu0COCcaTtJurXCNLSM2si ql8oRk3ibHKp6ahEMgP6kieoqcF4NPJhVDGYIS6BcPMfg2xfEV9XhPfz9tNLixDUhSa5 KE9g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769394672; x=1769999472; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=ymnLBLi8khxZIsCQL9bJnfvhV+yX6mpInM8DP2CqmnI=; b=pHxK8mEI/zDFILWN/FeL+XwPJtrVoExWuAxVympsU0z2RElNI5mFLmbZ7P7Cp+Al2B Qhw4CXleO8NufQhyHYncuoRSSswWpAfKEXDgj9RJmCTIJk3ERIoiuaAgzuVMny8+PaTz XQXis/vI2G/nW9LktCZm2a5hebruDhSTEWSDG9Jgkyqr4Hz9278NQAEH3dd+dxfbB/T9 qcKC14u85HsqKUJpyLcl85JsAK3SRD3xljD7+mCIu2xJb85dK+o/C7iRVAKC9I72t2GJ VzVfLa6OicA9+LIq4s90Hz2iY6Psml8OMXaqQHbIqvMZ7ycQkAyjtvrZtgr2JIjjfRms 2Npw== X-Forwarded-Encrypted: i=1; AJvYcCWOzstlS/HyUqmOfaoC09pgMn6XYz7JNEHvL7iO9Y2VomuUQ5scslZiEZDzIEX8P3GUi3Um7MvDZMs6gAk=@vger.kernel.org X-Gm-Message-State: AOJu0Yy3PGkhvqwcRv2RjDHia5wRvxvtWEX8ZzpZ3HOr+SVGvbkSaDbt HEJJ5aJpGdLKKvyJaOxdRm6OfTvwo2QBdYs8bJ9me2kSNQ4oNafe+Z2A X-Gm-Gg: AZuq6aKdDEuhvXOGAlhvHRYuJYTp6N6IZFScPHg8vcO+Rzg638lE0FtJTE3eT+HhuKh AmdPwJGTXt4JzIDzgaKNXmmqbz9fi/0HFW6NVY6fXtYy+AjLP/SD2SvKgMJYNPpMR0Z2p1XxeHz ovXOQXWftWCPBc+xr6nx1iJUTZ0LvewU9bBp4FNbU5i7/Frkk9mYs6DHtwD1guzmboFFj3q+Q+n Nx+14jvQPT9VG4+I88lVA7dgEIylXOM0uutwmvWB6HVdcAKM9ow9C6Fvo6+plQK25vZ13swCrhR vU62Vdgxl/7n+uYzCI6n8PjlKWXKpudkflMvxnDWQ/9XTJttbyH4ZYNeyjdFF//rIz+Z7+XA27F 1WcIZp8OWw+FDZ6v/akmS+gurioAKGElHFkvzYEW1V1gSBWQDssaEYCYw5dzmbFT5QN8Koa/Pcy OLbt7jdkSxMlO/1TIMNLmESJM2BU5YOxhF9iNZv0A40rYRbko0tEEX4QhBf25ECBw= X-Received: by 2002:a05:7022:6285:b0:11b:bf3f:5240 with SMTP id a92af1059eb24-1248ec0e28amr1564767c88.9.1769394672048; Sun, 25 Jan 2026 18:31:12 -0800 (PST) Received: from luna.turtle.lan (static-23-234-93-211.cust.tzulo.com. [23.234.93.211]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-1247d91c52bsm17212277c88.6.2026.01.25.18.31.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 25 Jan 2026 18:31:11 -0800 (PST) From: Sam Edwards X-Google-Original-From: Sam Edwards To: Xiubo Li , Ilya Dryomov Cc: Viacheslav Dubeyko , Christian Brauner , Milind Changire , Jeff Layton , ceph-devel@vger.kernel.org, linux-kernel@vger.kernel.org, Sam Edwards Subject: [PATCH v3 4/4] ceph: assert writeback loop invariants Date: Sun, 25 Jan 2026 18:30:55 -0800 Message-ID: <20260126023055.405401-5-CFSworks@gmail.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260126023055.405401-1-CFSworks@gmail.com> References: <20260126023055.405401-1-CFSworks@gmail.com> 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 Content-Type: text/plain; charset="utf-8" If `locked_pages` is zero, the page array must not be allocated: ceph_process_folio_batch() uses `locked_pages` to decide when to allocate `pages`, and redundant allocations trigger ceph_allocate_page_array()'s BUG_ON(), resulting in a worker oops (and writeback stall) or even a kernel panic. Consequently, the main loop in ceph_writepages_start() assumes that the lifetime of `pages` is confined to a single iteration. This expectation is currently not clear enough, as evidenced by two recent patches which fix oopses caused by `pages` persisting into the next loop iteration: - "ceph: do not propagate page array emplacement errors as batch errors" - "ceph: free page array when ceph_submit_write() fails" Use an explicit BUG_ON() at the top of the loop to assert the loop's preexisting expectation that `pages` is cleaned up by the previous iteration. Because this is closely tied to `locked_pages`, also make it the previous iteration's responsibility to guarantee its reset, and verify with a second new BUG_ON() instead of handling (and masking) failures to do so. This patch does not change invariants, behavior, or failure modes. The added BUG_ON() lines catch conditions that would already trigger oops, but do so earlier for easier debugging and programmer clarity. Signed-off-by: Sam Edwards --- fs/ceph/addr.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/fs/ceph/addr.c b/fs/ceph/addr.c index cdf11288d6b7..4e392fc70d33 100644 --- a/fs/ceph/addr.c +++ b/fs/ceph/addr.c @@ -1663,7 +1663,9 @@ static int ceph_writepages_start(struct address_space= *mapping, tag_pages_for_writeback(mapping, ceph_wbc.index, ceph_wbc.end); =20 while (!has_writeback_done(&ceph_wbc)) { - ceph_wbc.locked_pages =3D 0; + BUG_ON(ceph_wbc.locked_pages); + BUG_ON(ceph_wbc.pages); + ceph_wbc.max_pages =3D ceph_wbc.wsize >> PAGE_SHIFT; =20 get_more_pages: --=20 2.52.0