From nobody Sat Feb 7 11:31:41 2026 Received: from mail-pf1-f195.google.com (mail-pf1-f195.google.com [209.85.210.195]) (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 536182E5D32 for ; Wed, 31 Dec 2025 02:55:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.195 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767149734; cv=none; b=aLPnq3MWGlaEMiul6mMEW5ImgKSyLJzqvSPbKIiJSj52iPC1vHYYRNukQQmLa4YWv5YJjgGfwonfJCY/nkmngLqmrVXGFJmUym0C70CrYMtgi8FHDRyOtKGq13z/m57j7bC/O2SGWzdLa4ZtysPp8+sJmLTd8dXMyrlFiaWaeS4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767149734; c=relaxed/simple; bh=7x51uiDaTktolV+LzMU7zA0PjIHxRzwQBudHNGCpDGg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=SJWIsRPFOadbvqGrqdfim2LyZd2XdEkxPddUcELvAYzYT6d9lkMmY2F9yRgDimKs35uxOJIEshMkrD3HZjXwFU5F2bREJ+mPEn2iv1sjt9Cg4+Tw2BLpIJgXLXFnddBe64HNe8IcimguM4J1ImBYxzParyJKO10+ENUG9pCaaAw= 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=eEe7MnOq; arc=none smtp.client-ip=209.85.210.195 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="eEe7MnOq" Received: by mail-pf1-f195.google.com with SMTP id d2e1a72fcca58-803474aaa8bso3777203b3a.0 for ; Tue, 30 Dec 2025 18:55:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1767149732; x=1767754532; 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=A6vlMYfzzrfVusqphG0GGHNwZxDj4Zq+5OFoT9T7pH0=; b=eEe7MnOq6VCPR+jJTNEjh4SyGDDkWRbtjjaHtchvBt0hBh+UAfPA8KiyEdOdzwnt7h yQsakuVbZl878/FoDsuSZSpjCkumIWYr2s+ALH4k2oGktfmGv76ErQG5akDa6nWKo18+ 0YwBZ0ya706JZk5H762V2EEiF0hpdl5eqaCfcEAjYD2FSvNN6FH/ae1PYZpE87TOMK3l e5/t0qV8zwtihC6wxe1xzQwuRXY7D+TGvFwLrEK1SIiN5CUE9cVOP48ChUGyObF6jfwM Uw7hKamidCfyfd45Ztb8KHMk8QKQLWBB3DCrFxQfu5e756MWRKMCC67jt78TPP9P08O7 TqvQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1767149732; x=1767754532; 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=A6vlMYfzzrfVusqphG0GGHNwZxDj4Zq+5OFoT9T7pH0=; b=tDF9gUT82LzuCxvE7Sub2PvMStMUePrzrbKv3dodM3xxezjDCEXlZRKy2iw6czuSaQ W+tady9axPwkd5bANRh8KrdLQZKZPxXj4xxV32nfU3HviuflmenVWoVGUthpCDmZFM3Z IvxtJmwdaudQcw3O9IB/161PMRD9zH+jT7dw6L9iIjsOkCaN+Dcg+c2li4byYXxWAITH szOI5iID43xk6E+lA8njIIESTOROgUkw6fa52B5+kzfwUekIa3VzTp9mT7wnVHJhijWY Wnw158I+dYjqU1b7moi190AIG50YoQR+woPc83VCenXXqvi7Y1oHZxQeS3OzLm5sfNrF B86A== X-Forwarded-Encrypted: i=1; AJvYcCXhp1y7e/wteRNCaLaQ4vfWjaUirOylTYrjMVZ5gnDC6u8VMrOSD7se9LdsMM3LfffRaWRGROzStYzfXc8=@vger.kernel.org X-Gm-Message-State: AOJu0YyOBrAtH0siP/AJGR0qZMuEl/DhjwnZWPldNjvYIY92D/Vuu0iy 60LkXocLXe29rbWEUkBOU4dpYK4+PYxjReWLPBK2zXMTxImayR0KkIlT X-Gm-Gg: AY/fxX45G7FO/c9CilA1YMY3eMqK4X+OMqqfRifiyD76ZPUVHHM6GAmjvo9podcVLHn vbKu4gzsY7jBT4qe0+4fwDTkwwEnK22GKRM7njj6icRq/B8NbI4EdRYjxnVtnb9i8AxABIpFQ64 apyv5S1yCj7v0pKq0p2poW26pQEkCQGPDWYz3Sz6GQ9vLhIgw8kTv42LxXRpsbNYxouDCRtcrqG hmJd1fxWMEtNxJm1T+Nen02ClHrwfLwU1+jAHyYQPGwPmoXzqtx8ghgrNkokGcaHmL+6BV3t2MI 6aGtnPjq3/bGJlas4vjjF5QPRt2HClP+FygSKRAMRhU0NBfn+f2/lkSFG31voUomntl43o6OkGk fUOEaNAXi1/Z/7jCctl40aVp9x6vf77IZeGMX1Lldz1J7auuAh0asV0XXldQUEgp9V6xXc8tM+Z M+LQ== X-Google-Smtp-Source: AGHT+IEbU2+Y00aMWNdc38w4hjHwqdRtFca243nmnZxlmhfr5urwXm9ogf2dF3svZ9Qb+AeuG4fIeg== X-Received: by 2002:a05:6a00:4514:b0:78a:f6be:74f2 with SMTP id d2e1a72fcca58-7ff5284da68mr35782590b3a.5.1767149731611; Tue, 30 Dec 2025 18:55:31 -0800 (PST) Received: from celestia ([69.9.135.12]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7ff7e892926sm33623646b3a.66.2025.12.30.18.55.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Dec 2025 18:55:31 -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 4/5] ceph: Assert writeback loop invariants Date: Tue, 30 Dec 2025 18:43:15 -0800 Message-ID: <20251231024316.4643-5-CFSworks@gmail.com> X-Mailer: git-send-email 2.51.2 In-Reply-To: <20251231024316.4643-1-CFSworks@gmail.com> References: <20251231024316.4643-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 the previous two patches which fix oopses caused by `pages` persisting into the next loop iteration. 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. Signed-off-by: Sam Edwards --- fs/ceph/addr.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/fs/ceph/addr.c b/fs/ceph/addr.c index 91cc43950162..b3569d44d510 100644 --- a/fs/ceph/addr.c +++ b/fs/ceph/addr.c @@ -1669,7 +1669,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: @@ -1703,11 +1705,10 @@ static int ceph_writepages_start(struct address_spa= ce *mapping, } =20 rc =3D ceph_submit_write(mapping, wbc, &ceph_wbc); - if (rc) - goto release_folios; - ceph_wbc.locked_pages =3D 0; ceph_wbc.strip_unit_end =3D 0; + if (rc) + goto release_folios; =20 if (folio_batch_count(&ceph_wbc.fbatch) > 0) { ceph_wbc.nr_folios =3D --=20 2.51.2