From nobody Sat Feb 7 13:41:30 2026 Received: from mail-dy1-f173.google.com (mail-dy1-f173.google.com [74.125.82.173]) (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 E9CDF2BDC05 for ; Wed, 7 Jan 2026 21:02:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767819730; cv=none; b=srsrzR90PL2kgnsIRWTE1CjjVzxzdxWaI5V5Ord/tqjyZyb42Y9DPEokWUJOQg+kWVOYOWs7mU4SUPfQTnoMDVcjlHbCR1FK8s6T7in3IdkPECZED3c1UGUGqtGxM+arMWfewHXLojpeDWiPoMFQc7rHOdUaC8Cnpnm1AM5k9io= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767819730; c=relaxed/simple; bh=MH9ItMzBcZTluvZqALSZ1F57m7cvQEt2yG0/5jKRRIU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=GSaG9gEV8OADpDm2TPxqrSsdEtkI/FGLw3kpaiPAgLQf1Xykd9VagqJzQvKMklHUxl53eKQbcB7qFy8DV7O2DVBdiDOhQmuqhome+JylYHFl/bKDTjuOf2tspsbe8YTkZHUIeV7s1C4jmBWBLE/lrDqS6vrdeEKjtrH+Z3hImKY= 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=ci4kyi3z; arc=none smtp.client-ip=74.125.82.173 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="ci4kyi3z" Received: by mail-dy1-f173.google.com with SMTP id 5a478bee46e88-2ae29ddaed9so623804eec.0 for ; Wed, 07 Jan 2026 13:02:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1767819728; x=1768424528; 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=rI9ht6zLDnTdHsEUK/2YLyBXC/hQ/zyK3ZFH+/rd3ZU=; b=ci4kyi3zD2j7KiLUjQkIcDU7vuOsX6S4mJZQ4AVy+npgOrbsZh/gpA6dORUo6X6ds9 Tw8napnxETN5al9CCa2jPUtv+17djSqaDZqFicacXROVkiQlgyo6Vp4M1aXCupq0tRUQ vJVtuOlv6CEzy3AIwBCADL6oDk2iqiIGlzCNaat5/llGCRur5W7Wm4narV0IDWbTOz1Y Y9ne0NH9h9fdsqH9bQh0aeKxp5rp8DPdnIQP+9Qqs+VPUcNxVQNN+RN89Fk47Y7QNU6Z laBqZktA3/2NYT/Bi993LIQGBXVsEnfVQVXNXJO+9OhYjWN/fhPDLGQfeb+xo0vTxV/K Z3Hw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1767819728; x=1768424528; 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=rI9ht6zLDnTdHsEUK/2YLyBXC/hQ/zyK3ZFH+/rd3ZU=; b=lBd7xvgF5r8XY4wXB1VtL3BvrwQrov1anuqX66PeiirY91hzPoRg4wgL44bDyFr4Jd wlv3Yfs1emM4lXuUcU4v+gbApCnWk0zi/m7lB0XvYUmT/XVjPJXadMNTL2Zb5E3uQD1V pgddsGCrrKwm15TNvO5SUBlaVWZ054OkcMemj+h1IU3XmntQ2pdbuBl8UwluQ69H/w16 +iYPW04qEG9mVPHnr3DFKBtbsUEl6ho/rlM/KHmnbK++3dPMjOuIDa1CzQFSaVADHDgP 1f4X2MuzCuq34RcFnxNDxmQ9+ywuRm0xCOH3I9lzSmGJC4iINw3Ghoqwlu0arFEWWiRJ X/4g== X-Forwarded-Encrypted: i=1; AJvYcCVXs/78yloSp5+WG6gDLzYgEkhui3HlBV0MzPuMRtjUBeyAGIOcJr41pZLOtukBFibiV/QREcVkp6b/YRk=@vger.kernel.org X-Gm-Message-State: AOJu0YyiKwkreFqygMvoKmQ2BGaqgyzhBtR9QZ5RMyP1wy4v5dNpzbOu 6w3G9ymH1zqVhEsL82C8/oe0ATGV4kW9hrI+5kFYVDXQ1PQVziyjyZTjLXhp/A== X-Gm-Gg: AY/fxX6N3Sa0jZq7Ygf/kX4rua+gKiFlNGCN8pD/YBcQHq2G7zl0qzRtAtERxmMp5ii uYlJwuRu1Dwk3wW0CSup3aWpc0Y3CXS3N8Ey3VpCgNSsUg5y857pu7ym8SqFzouyIlLucHKGQ0E +HclPKiMcg1i+EEbw54OQB6Jd1P7KDypEY8s9n69skpHmlAjFKyXUiK/UQlpRV4DUg2koIbDuDh ivG6vZRsFt539tH7MPq327vE2Iymg+ilPEbXSdSMjp+w+Dju+CHHq841cn6PFkxs4B2FSC8Lcmi LcNEXQcRIF0WJWDNNzCyqPH3K2rt/1Do1glHiCZXsGX0iq60yF7WZTJoLgH1IqM6HHT6PqNnaxK LpcdM4lU56+VR/4lRdqm+dKLsPcFeNbR/LgB0idx5XBkoaXuzOXCS+N0fl2MVSeqRBfTSVyzusT rVvelRJLaOstsEE851RtXEHuLEZUK0J1pnP+RYxTq6P4qNFNgijrVlzfxX+5oE X-Google-Smtp-Source: AGHT+IGz/j2Ai3L0sVPhta32pFiq7xX5jIWUYZAFCkfFw3N2nVApKTu2oj9sPXVOchzP/JfTY8hCxQ== X-Received: by 2002:a05:7301:700e:b0:2ae:4c10:138c with SMTP id 5a478bee46e88-2b16fe5a43bmr3571639eec.11.1767819727866; Wed, 07 Jan 2026 13:02:07 -0800 (PST) Received: from celestia.turtle.lan (static-23-234-115-121.cust.tzulo.com. [23.234.115.121]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-2b170673b2esm7730320eec.6.2026.01.07.13.02.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Jan 2026 13:02:07 -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 , stable@vger.kernel.org Subject: [PATCH v2 1/6] ceph: Do not propagate page array emplacement errors as batch errors Date: Wed, 7 Jan 2026 13:01:34 -0800 Message-ID: <20260107210139.40554-2-CFSworks@gmail.com> X-Mailer: git-send-email 2.51.2 In-Reply-To: <20260107210139.40554-1-CFSworks@gmail.com> References: <20260107210139.40554-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" When fscrypt is enabled, move_dirty_folio_in_page_array() may fail because it needs to allocate bounce buffers to store the encrypted versions of each folio. Each folio beyond the first allocates its bounce buffer with GFP_NOWAIT. Failures are common (and expected) under this allocation mode; they should flush (not abort) the batch. However, ceph_process_folio_batch() uses the same `rc` variable for its own return code and for capturing the return codes of its routine calls; failing to reset `rc` back to 0 results in the error being propagated out to the main writeback loop, which cannot actually tolerate any errors here: once `ceph_wbc.pages` is allocated, it must be passed to ceph_submit_write() to be freed. If it survives until the next iteration (e.g. due to the goto being followed), ceph_allocate_page_array()'s BUG_ON() will oops the worker. (Subsequent patches in this series make the loop more robust.) Note that this failure mode is currently masked due to another bug (addressed later in this series) that prevents multiple encrypted folios from being selected for the same write. For now, just reset `rc` when redirtying the folio to prevent errors in move_dirty_folio_in_page_array() from propagating. (Note that move_dirty_folio_in_page_array() is careful never to return errors on the first folio, so there is no need to check for that.) After this change, ceph_process_folio_batch() no longer returns errors; its only remaining failure indicator is `locked_pages =3D=3D 0`, which the caller already handles correctly. The next patch in this series addresses this. Fixes: ce80b76dd327 ("ceph: introduce ceph_process_folio_batch() method") Cc: stable@vger.kernel.org Signed-off-by: Sam Edwards --- fs/ceph/addr.c | 1 + 1 file changed, 1 insertion(+) diff --git a/fs/ceph/addr.c b/fs/ceph/addr.c index 63b75d214210..3462df35d245 100644 --- a/fs/ceph/addr.c +++ b/fs/ceph/addr.c @@ -1369,6 +1369,7 @@ int ceph_process_folio_batch(struct address_space *ma= pping, rc =3D move_dirty_folio_in_page_array(mapping, wbc, ceph_wbc, folio); if (rc) { + rc =3D 0; folio_redirty_for_writepage(wbc, folio); folio_unlock(folio); break; --=20 2.51.2 From nobody Sat Feb 7 13:41:30 2026 Received: from mail-dy1-f181.google.com (mail-dy1-f181.google.com [74.125.82.181]) (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 2D9412C3277 for ; Wed, 7 Jan 2026 21:02:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767819732; cv=none; b=auUVj7dya9LE+nBCZcZBVGNBQS+TV3qvgaPOzi1ale4VsotSedkr5130YbAEy9N7xpnSPfX6IndJpW6b/Vc4j4f5sq5uMLRxVCEg++Ss3Ps+uKwWzvQF2BCGN9AQobu8YicJPJmSQ+UfZnbhXBJonIqwIUaeuLVyrL9jjK7IPzA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767819732; c=relaxed/simple; bh=+OMCjLpYjNGGYfZdJjYQd5xrfdW6cvuAZrYjo1yzsPw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gSU1rTBYmhHVbq4EQ4Aqy2I5eCYm+zjn9+6ygNyg3wHt2XRsvhNp7YKrPyC5iHgCepHTIlza0h7WZ65q2auVKCFQoVu3XrUVYSyQ4yaA62WReqt6y6jVUJvML0E491GmKngkxBZHorC1VRTI7RpL0YCGUP+9wuoVmoeMyRktp6A= 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=dJEfy+e3; arc=none smtp.client-ip=74.125.82.181 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="dJEfy+e3" Received: by mail-dy1-f181.google.com with SMTP id 5a478bee46e88-2abf5900cd5so2144825eec.1 for ; Wed, 07 Jan 2026 13:02:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1767819730; x=1768424530; 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=GD9+M0L1TL+nHtGjY77JqppAv2xqxZhHU8cYw4+7xmc=; b=dJEfy+e331TidlLiFpSFFrBPOS797CIQ7A5F/1RdsRprkf5blG5ocgPphFXMjJ2VTs qldT2EHbWo8YF/XD0m80NbNlpgWufKWgXkhISKPnraVuy9NC1bPXSh9CqMmsdMVlqOmE y+EvALPA2oGkRtKzq3XcVULdycFe8x+i0KcIx3LjhDfoAIvbt2qK3sgGWiFRrqJKp174 VttQxjx1vQirpmU0ndKAyrwlHe9NkZSLBQadvKYHFEA3yrzQIICuKh2gsiWqAibc6LE0 +v8bk7nH+PqZDd+yURKNCoSB4QrX3pkVy6wHzidPgAMXS2d+x4n7p+LbmSDphuH7Fv9k ngJQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1767819730; x=1768424530; 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=GD9+M0L1TL+nHtGjY77JqppAv2xqxZhHU8cYw4+7xmc=; b=GO67qsneTZDJ87OR0fEyXfuWNVDhPaAs+7r80ynnTUD6cGe1tN2ovS8nNA+5arOKI8 zknTUEMLSnOKGyzpSrzTvhNi9MSliTXIQYZ5DVrBmWTy6oIFqIE/WQSpYFn8HGrPLozX FohI5FOfw0FRRyPrRelZbnNMUuVWPXRs7h/dNkC9X0ql002Dyy8p/EnrFgyG8m4J70fe wPPjEdUvbS+aRYj4lcF4d2uhH5yCwJZM2HIhRfAiq28KOwrbPb7jr3IDfJJNIuCKb2e8 0Syo48DmXOUF9HSUXG5ovfUG2GbJOiIxTOTF0yDSaBwoTVEucsPL3rTrCQxd5Z6/VqLu cMow== X-Forwarded-Encrypted: i=1; AJvYcCW1AIwPVW2XbRUBKNo5EAEDkd2b3Fog/4vEwGUH7NjhgZp1jfA5f0JwFnIPEDhz2QC/h9VLty3Cyk0Yv8U=@vger.kernel.org X-Gm-Message-State: AOJu0YwDdod4ij7T4B0OBc6Q2CN9ME191jlc6BCaOfxKrIlOEao46hGt SYuw2sgZb1aSe6deV+spIvEdACuAb3km1XdeNM2pqZgTWtf1RZ9BnHSP X-Gm-Gg: AY/fxX5ueEMLHvbQyHauXuEzDWMXkEV2M0ZQbI+U76h+iMnJ3FUnTIPMJDAEN3LX0si Wt5M3idHH7eLag+m3KIDAvuBS/7I7BxIVzCpAeF+d1W+FuBK0AFRmu3H4SGYseXJ85Fkm9xnbH9 +/lMIIdZ6AedA07VxnTBb8l5PWjdVa80KQUd1SZGWz2kQ62j/YeQ/GdWiqdFfUJ8cMLqTMUVYIE DHMahLlLCMVIXdGG1xgWzrKqF7WYL9RTrL7eyk6Indb43BDeqyJxLhNVO6jDk1+DwPRAq1NAyQA UvEoSR58OC8I0hjpCITmydoY7jJae8gzSENi+E+IyqxpLtKzHqD2+0IL9cdCCvj0yNWCXM6NDNG O2718rnpEWjJAzXXw6m+T3H4DjjK9VnmY0ko8SH03wH7N1yWFmILWVkpbaxgfxCtN+z2xTaE6G3 6cjWFeSqCHoxZD1EcqZNTygp7K2W2uhahiQpgSePNr+1spkJwsl1JCSZ1d4iBE X-Google-Smtp-Source: AGHT+IFmRzf4pdV3GuAH14ZP8NjG8Wy8k2FewwYwSLBXQ+brWhVevt7B0bSV0EESgMlR/cm8NffJRQ== X-Received: by 2002:a05:7300:8aa4:b0:2a4:3592:c612 with SMTP id 5a478bee46e88-2b17d2d6606mr1893273eec.35.1767819729839; Wed, 07 Jan 2026 13:02:09 -0800 (PST) Received: from celestia.turtle.lan (static-23-234-115-121.cust.tzulo.com. [23.234.115.121]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-2b170673b2esm7730320eec.6.2026.01.07.13.02.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Jan 2026 13:02:09 -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 v2 2/6] ceph: Remove error return from ceph_process_folio_batch() Date: Wed, 7 Jan 2026 13:01:35 -0800 Message-ID: <20260107210139.40554-3-CFSworks@gmail.com> X-Mailer: git-send-email 2.51.2 In-Reply-To: <20260107210139.40554-1-CFSworks@gmail.com> References: <20260107210139.40554-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" Following the previous patch, ceph_process_folio_batch() no longer returns errors because the writeback loop cannot handle them. Since this function already indicates failure to lock any pages by leaving `ceph_wbc.locked_pages =3D=3D 0`, and the writeback loop has no way to handle abandonment of a locked batch, change the return type of ceph_process_folio_batch() to `void` and remove the pathological goto in the writeback loop. The lack of a return code emphasizes that ceph_process_folio_batch() is designed to be abort-free: that is, once it commits a folio for writeback, it will not later abandon it or propagate an error for that folio. Signed-off-by: Sam Edwards --- fs/ceph/addr.c | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/fs/ceph/addr.c b/fs/ceph/addr.c index 3462df35d245..2b722916fb9b 100644 --- a/fs/ceph/addr.c +++ b/fs/ceph/addr.c @@ -1283,16 +1283,16 @@ static inline int move_dirty_folio_in_page_array(st= ruct address_space *mapping, } =20 static -int ceph_process_folio_batch(struct address_space *mapping, - struct writeback_control *wbc, - struct ceph_writeback_ctl *ceph_wbc) +void ceph_process_folio_batch(struct address_space *mapping, + struct writeback_control *wbc, + struct ceph_writeback_ctl *ceph_wbc) { struct inode *inode =3D mapping->host; struct ceph_fs_client *fsc =3D ceph_inode_to_fs_client(inode); struct ceph_client *cl =3D fsc->client; struct folio *folio =3D NULL; unsigned i; - int rc =3D 0; + int rc; =20 for (i =3D 0; can_next_page_be_processed(ceph_wbc, i); i++) { folio =3D ceph_wbc->fbatch.folios[i]; @@ -1322,12 +1322,10 @@ int ceph_process_folio_batch(struct address_space *= mapping, rc =3D ceph_check_page_before_write(mapping, wbc, ceph_wbc, folio); if (rc =3D=3D -ENODATA) { - rc =3D 0; folio_unlock(folio); ceph_wbc->fbatch.folios[i] =3D NULL; continue; } else if (rc =3D=3D -E2BIG) { - rc =3D 0; folio_unlock(folio); ceph_wbc->fbatch.folios[i] =3D NULL; break; @@ -1369,7 +1367,6 @@ int ceph_process_folio_batch(struct address_space *ma= pping, rc =3D move_dirty_folio_in_page_array(mapping, wbc, ceph_wbc, folio); if (rc) { - rc =3D 0; folio_redirty_for_writepage(wbc, folio); folio_unlock(folio); break; @@ -1380,8 +1377,6 @@ int ceph_process_folio_batch(struct address_space *ma= pping, } =20 ceph_wbc->processed_in_fbatch =3D i; - - return rc; } =20 static inline @@ -1685,10 +1680,8 @@ static int ceph_writepages_start(struct address_spac= e *mapping, break; =20 process_folio_batch: - rc =3D ceph_process_folio_batch(mapping, wbc, &ceph_wbc); + ceph_process_folio_batch(mapping, wbc, &ceph_wbc); ceph_shift_unused_folios_left(&ceph_wbc.fbatch); - if (rc) - goto release_folios; =20 /* did we get anything? */ if (!ceph_wbc.locked_pages) --=20 2.51.2 From nobody Sat Feb 7 13:41:30 2026 Received: from mail-dy1-f179.google.com (mail-dy1-f179.google.com [74.125.82.179]) (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 E56172D641C for ; Wed, 7 Jan 2026 21:02:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767819736; cv=none; b=jLFk8jiV1q/iB4TkfF0RmE0cW2vGkbq0PqE90v6cEjyfhwzUQ0QUsL78vJSxRq1tDyj0hVYE/uRBw1HsJ8NSsx82mRvCXPYPgsLoK3jNCR0od49V37iKWiQyHhlyctyQD9L90kDh7hYPtXVYVtYDnpcgfw58rF//KgsoUZipSwA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767819736; c=relaxed/simple; bh=OToRqjvmUYJ/hQ/uywMC5tHsYvK3gXP3yNUZuoCsk/k=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=N50pf0P10t5953hSpHRbw1iPAUEcNEFYDVUJ6INs3AGBn5xwuXyBtxLlXOqFE8TIKYYPqBByWVnahUbAWf5KzZQ/s0ymMn+i6yJoXzD78o5QGXoh4gYFc5SstPShNebJ1FaQorZZwTjUxXKK9Zr0XQUbPsVnUW5Malas/xxHaz0= 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=J53VGxvM; arc=none smtp.client-ip=74.125.82.179 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="J53VGxvM" Received: by mail-dy1-f179.google.com with SMTP id 5a478bee46e88-2b05fe2bf14so2530482eec.1 for ; Wed, 07 Jan 2026 13:02:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1767819732; x=1768424532; 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=StC5RRMJpz+kQrLWAhYbYP3HFYIHTdt3vEQL2gvPaOI=; b=J53VGxvMIZxqirtQX3wYHg+/odvWOpaJHAskxJ3YBshcYnKwwF3R4WbljGmaRUg+Qs /xM/QUDAH2e4UOswRlUSenqeRQHu9du25kCP8hgxpxODXi+BCkpSLQ6SqFg425Uc3h/h FvT75zjj1BcV2WJ0n3YOWALK11q/QXQXdrkarHvM9KjaW+OmVv4BSNpY3JzubrEcPwbc myhm6x5d3G3GaVDNxgHulCWD37Uh0mcDQFfjgC47Giq4JtqmVCyNjFKHe4zio9wqD/lm TS3qlJpzAhkku6vYjEHjy3j9CKPkdJ0Bo0iu34g73a5cVVd1STbIUpHtOub7fNjfbiEo VeIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1767819732; x=1768424532; 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=StC5RRMJpz+kQrLWAhYbYP3HFYIHTdt3vEQL2gvPaOI=; b=hD05sqygNQM65JouFz40qHrzSeFRnRl9ZHb24q/sVe3tg8fHRdQbm+w9Xj+8D5NigZ A/qsDQ2noLTtlgYjiUxlr1J1qmE54/MRwqO5ESSgcLgdVklGSaoCWXTzl+076QO+aeRt dfOh8CsQEq0XkWk+lWTtbvR/xytueWEsKbzkGLHmaTnOXMYYXKVFVJ/qLekA4urGPK8K 2pYgCACEhDMhyh+HuARkkrtVqUN2aXfMN2KD853/k5wyU87XeOp3V1+eHrhupvid8dil RO8wVozdFwzsckR4Ror/7n7+rdJ9T+03qQsrdoeZQ5fc7BJ6tGmn6bLUPWlAG7Jz7+o+ nowg== X-Forwarded-Encrypted: i=1; AJvYcCUowapa/itRr/EB4yhM4bFlYVpSc7KagV/MWNlaWWLwSPy7DPIpQ+zao/WN5KA3NWT+7TkfR3pqT+hm4uM=@vger.kernel.org X-Gm-Message-State: AOJu0YwZLJqO3TkidEZb90Jw8wZgAq0NGtRPdPLi70bySRFf125q0cPx 66RXtuovMLOaqX0hDydoWEQXlx/JDG9KHaQ54AVd3EWP2LT6E6dcYPx9 X-Gm-Gg: AY/fxX5qRXjdpfOd0lbiuOT9YXFlPvxCugm97LHnxb7DvQz+jrh6uRX5YQ1ZVY6S5/6 GpRRDU2VF8Ncn96IXBkXCT3gIl7tMGNguWdt6RCEpZeQ9njzRbcddtR4LP1P4waHdSxTqK/LYoe CLxetQDNAFmBfffOGh5yU+9vFD2p/dAAmrglDkFb4YZv6p1BTSon24PIN1RE/5xU7aMZrrAUxFn bsIMmEs4ZO0oTnNWOrvpyKzM9/4tv8f4Qgy+e5rAfmGB+NCKOTQ/R1X3Wj6alMieyX8EaNnXsTi FPM6b8+AKTx2AMoYqFUQDBPrUAqYcu42vlJMenVJqOFCis1Zu5bfsB+A6MLx785fDxDKNoq/2Mo 5DKAgH+9jP+xfX6s7MJ5ibEIntG2gg/jxFbThls+wINSkQbSR2SLcx1iqJnmWUBQQGPHL6xb3/B jIm0l9sN3cAjlr8+Vnah1CnFVaTTCTUD85eKHi44c+6piZ4xEzHl++g7wCj/Vt X-Google-Smtp-Source: AGHT+IHsusTxGdP1PS4z/IoCh9itAIP1JdP4x5wJw6BXtiBXvisAnQNe01ae9GbbYPWzAyzvMWqFZw== X-Received: by 2002:a05:7301:e2b:b0:2ae:5ffa:8daa with SMTP id 5a478bee46e88-2b17d200bc3mr2817972eec.5.1767819731857; Wed, 07 Jan 2026 13:02:11 -0800 (PST) Received: from celestia.turtle.lan (static-23-234-115-121.cust.tzulo.com. [23.234.115.121]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-2b170673b2esm7730320eec.6.2026.01.07.13.02.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Jan 2026 13:02: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 , stable@vger.kernel.org Subject: [PATCH v2 3/6] ceph: Free page array when ceph_submit_write fails Date: Wed, 7 Jan 2026 13:01:36 -0800 Message-ID: <20260107210139.40554-4-CFSworks@gmail.com> X-Mailer: git-send-email 2.51.2 In-Reply-To: <20260107210139.40554-1-CFSworks@gmail.com> References: <20260107210139.40554-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. The ceph_submit_write() function claims ownership of the page array on success. But failures only redirty/unlock the pages and fail to free the array, making the failure case in ceph_submit_write() fatal. Free the page array (and reset locked_pages) in ceph_submit_write()'s error-handling 'if' block so that the caller's invariant (that the array does not outlive the iteration) is maintained unconditionally, making failures in ceph_submit_write() recoverable as originally intended. Fixes: 1551ec61dc55 ("ceph: introduce ceph_submit_write() method") Cc: stable@vger.kernel.org Signed-off-by: Sam Edwards --- fs/ceph/addr.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/fs/ceph/addr.c b/fs/ceph/addr.c index 2b722916fb9b..467aa7242b49 100644 --- a/fs/ceph/addr.c +++ b/fs/ceph/addr.c @@ -1466,6 +1466,14 @@ int ceph_submit_write(struct address_space *mapping, unlock_page(page); } =20 + if (ceph_wbc->from_pool) { + mempool_free(ceph_wbc->pages, ceph_wb_pagevec_pool); + ceph_wbc->from_pool =3D false; + } else + kfree(ceph_wbc->pages); + ceph_wbc->pages =3D NULL; + ceph_wbc->locked_pages =3D 0; + ceph_osdc_put_request(req); return -EIO; } --=20 2.51.2 From nobody Sat Feb 7 13:41:30 2026 Received: from mail-dy1-f170.google.com (mail-dy1-f170.google.com [74.125.82.170]) (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 D67C62C0284 for ; Wed, 7 Jan 2026 21:02:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767819737; cv=none; b=WFfudXI7ZVxfss39DfHMP2k/wJENRHuEBwZ51QSLJrpFbAIPIgpSmfvbHUEFkOIvqZuGUqyftB2Y9l6o6cJw0WbYvZyaAJ0QvKWVcn2a0TZlS4RKPql9VeFEotSaDbQnqIfHeNoz5qhVpYZK707oq9m9gHZSJxf5UJDSSrEDDHU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767819737; c=relaxed/simple; bh=M+v5Vw0Jil/rA486zu+DiAOWZxQZQJUjs4l0t3TZ4tM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=puZFRO5F8NgwTcBp4/eKqDpMQ4ldIGHOzPMAKEcL3808397WRGf1SwEZLauOL/HjxVgJv4PZ0XIu7HRl/7ao7vyduxaxEj9suz9m4N7Yi/pEHB2mf+LEk0gyPLiilGH4j7V7qs2dQZGpQjlS8oXKyxZ/UZv1vJvCpcnvZYNAKbw= 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=dWVABuWR; arc=none smtp.client-ip=74.125.82.170 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="dWVABuWR" Received: by mail-dy1-f170.google.com with SMTP id 5a478bee46e88-2ac3d5ab81bso1525528eec.1 for ; Wed, 07 Jan 2026 13:02:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1767819734; x=1768424534; 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=0iYD+ioNTt6TfLHqUAr1a4Xg5XGaJpAZluY0IKqvlcs=; b=dWVABuWR+7O63Lh8EcYuo/R1NAj/wPU8/8jK03w9z4XHU0tXWlWvBgfW3eIXfAJwwi 6Fzqvifj4oqYmYdoSUXwH9nARwY3kX9oK+bQ++OqoG4zSI4OUjRKRcmQee4c5l7g1JPC h5K8e0wBOmUL6deZpS0Sf+Oh3gw7r/iEj9+ONDzaDEKxRT5HzhWVtHapaW9TMgc0w9t5 U+qZF6KN2GeJDr2bitwh7ytEdQlFxhMFMglHnMn+AUDUbbtdHOlhdNIGGempgG4fEmfz lXQFipsdmCD3ZTQ4abntp/K8E0bAIJZjFzyHCXIsr2bS6UJUf2M3bs2d2hdldDIKER+p W/oQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1767819734; x=1768424534; 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=0iYD+ioNTt6TfLHqUAr1a4Xg5XGaJpAZluY0IKqvlcs=; b=cIrFtVB66n9So+ymEmGl8WPrcF0Rh39v/n4iOa+Xr02PwZSGCbzmxSkZABnB6KCvjW p6VTmkL3KtnxjXgRehJqnWklWH0KaDh5W0EhtLK0IlwcctABWzG9wADW7U5ogJKHyMp4 mJlYs3oDMRwREo4N3ekVwEbgPzNFaodJecUXQRsXOn2VQHFywmLkvLKwTDxIhhAhKWvs 1Y+qihbYU6EinUVL8AhuLHvOTVI727/26QVNyRQHyDG3xTUJw3WqyaVoxdG8jrBkMjfY HrLm4FKz5GRn3KgWTzNwentEO1HV5QUw6NLuXiBsirQkwFE9nv/hbCvfMpqBcnzNxyCH 8Wbg== X-Forwarded-Encrypted: i=1; AJvYcCUbb4vYDA2Aq8Vlg0VtrL5lfou96DlpXvTFgoYMu1Ga+glbhoMbuU0iQ+dLT7Ycj+HAploptI6JxF4WhTM=@vger.kernel.org X-Gm-Message-State: AOJu0YwOSJk31COd8S4aJAQOUm3YBwPB4USEkLkMINTklBXn7ShVl0Vv udcwp5MDlBSfQQQq864UCi+kaCx5ypv06xp7Dm0Aj24YW+g2bBzTWkIn X-Gm-Gg: AY/fxX6qGIA31zbWmH/Yj8CgoEHqF7UtSuD6t5+R9ufAMUW0lEf2j4oewBP1cvh8wFr iCeQ8KHZX06xlho/bzL6qRi1bjFpinSHmfcl9Eo9kMk67njv0sqQYDX1p257cnT4cEiHHW8uUlH FFvdUGV8rxNSaDNL7Q3u8ZAbPeMZPAMvVTUvdJJCHT4w90a6L9DJTlmdlSrVsmQgPhjDRob961t MmgTn4xWbEHGLxKJA0k9xvTlCXEKTknzU9n5xvHNdPeGvS3cIVFpfsXwKlSWGbhKBaqHenQ2uwv VY9FLnqP6xLdilvFwPb5yZthut5jgCZ/0Bbg/cuIaklZkI1uyUNTQa+tsN3dZIWCSeYpgwSUkG0 NSeovt47C9KFmy3Qyw+Nqt+nxzv+5ofR/XWZL35tt27PCtiX/lrmao6KscKOrFeVgLNj5mohq8Q TStjuueX/xV1MQxhwihepoXHftQgOxaLSVwaeJYwTFDu1Kn5Sj9IdC6pJ4JTyE X-Google-Smtp-Source: AGHT+IERp97W8qGccAbwxhXAxSLBpLHQVl7RhoNKnrA6Fsbg0/9438GYXF8rBuCdpX/av5RsA8yPMA== X-Received: by 2002:a05:7300:2d15:b0:2b0:5bce:2f44 with SMTP id 5a478bee46e88-2b17d25199amr2080567eec.10.1767819733776; Wed, 07 Jan 2026 13:02:13 -0800 (PST) Received: from celestia.turtle.lan (static-23-234-115-121.cust.tzulo.com. [23.234.115.121]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-2b170673b2esm7730320eec.6.2026.01.07.13.02.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Jan 2026 13:02:13 -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 v2 4/6] ceph: Split out page-array discarding to a function Date: Wed, 7 Jan 2026 13:01:37 -0800 Message-ID: <20260107210139.40554-5-CFSworks@gmail.com> X-Mailer: git-send-email 2.51.2 In-Reply-To: <20260107210139.40554-1-CFSworks@gmail.com> References: <20260107210139.40554-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" Discarding a page array (i.e. after failure to submit it) is a little complex: - Every folio in the batch needs to be redirtied and unlocked. - Some folios are bounce pages created for fscrypt; the underlying plaintext folios also need to be redirtied and unlocked. - The array itself can come either from the mempool or general kalloc, so different free functions need to be used depending on which. Although currently only ceph_submit_write() does this, this logic is complex enough to warrant its own function. Move it to a new ceph_discard_page_array() function that is called by ceph_submit_write() instead. Suggested-by: Viacheslav Dubeyko Signed-off-by: Sam Edwards Reviewed-by: Viacheslav Dubeyko --- fs/ceph/addr.c | 67 ++++++++++++++++++++++++++++---------------------- 1 file changed, 38 insertions(+), 29 deletions(-) diff --git a/fs/ceph/addr.c b/fs/ceph/addr.c index 467aa7242b49..3becb13a09fe 100644 --- a/fs/ceph/addr.c +++ b/fs/ceph/addr.c @@ -1222,6 +1222,43 @@ void ceph_allocate_page_array(struct address_space *= mapping, ceph_wbc->len =3D 0; } =20 +static inline +void ceph_discard_page_array(struct writeback_control *wbc, + struct ceph_writeback_ctl *ceph_wbc) +{ + int i; + struct page *page; + + for (i =3D 0; i < folio_batch_count(&ceph_wbc->fbatch); i++) { + struct folio *folio =3D ceph_wbc->fbatch.folios[i]; + + if (!folio) + continue; + + page =3D &folio->page; + redirty_page_for_writepage(wbc, page); + unlock_page(page); + } + + for (i =3D 0; i < ceph_wbc->locked_pages; i++) { + page =3D ceph_fscrypt_pagecache_page(ceph_wbc->pages[i]); + + if (!page) + continue; + + redirty_page_for_writepage(wbc, page); + unlock_page(page); + } + + if (ceph_wbc->from_pool) { + mempool_free(ceph_wbc->pages, ceph_wb_pagevec_pool); + ceph_wbc->from_pool =3D false; + } else + kfree(ceph_wbc->pages); + ceph_wbc->pages =3D NULL; + ceph_wbc->locked_pages =3D 0; +} + static inline bool is_folio_index_contiguous(const struct ceph_writeback_ctl *ceph_wbc, const struct folio *folio) @@ -1445,35 +1482,7 @@ int ceph_submit_write(struct address_space *mapping, BUG_ON(len < ceph_fscrypt_page_offset(page) + thp_size(page) - offset); =20 if (!ceph_inc_osd_stopping_blocker(fsc->mdsc)) { - for (i =3D 0; i < folio_batch_count(&ceph_wbc->fbatch); i++) { - struct folio *folio =3D ceph_wbc->fbatch.folios[i]; - - if (!folio) - continue; - - page =3D &folio->page; - redirty_page_for_writepage(wbc, page); - unlock_page(page); - } - - for (i =3D 0; i < ceph_wbc->locked_pages; i++) { - page =3D ceph_fscrypt_pagecache_page(ceph_wbc->pages[i]); - - if (!page) - continue; - - redirty_page_for_writepage(wbc, page); - unlock_page(page); - } - - if (ceph_wbc->from_pool) { - mempool_free(ceph_wbc->pages, ceph_wb_pagevec_pool); - ceph_wbc->from_pool =3D false; - } else - kfree(ceph_wbc->pages); - ceph_wbc->pages =3D NULL; - ceph_wbc->locked_pages =3D 0; - + ceph_discard_page_array(wbc, ceph_wbc); ceph_osdc_put_request(req); return -EIO; } --=20 2.51.2 From nobody Sat Feb 7 13:41:30 2026 Received: from mail-dy1-f195.google.com (mail-dy1-f195.google.com [74.125.82.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 EFE302DA77E for ; Wed, 7 Jan 2026 21:02:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.195 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767819739; cv=none; b=BFnD8cnj2zzAfxmuowWA3+OQpQ2yeZ9RHfSzaZLHKv9VG50QYILMQF71v24nhXRrDM7maSpYoJD5fLCJZ/D2H7gwezSQ76Rj48r7MgVwVg4C796+uPW8vVegpFzR4u3Wbw4q19k4c55AbnkwXgULmU0lAm8NE56fmMwI1+QIZTs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767819739; c=relaxed/simple; bh=UlXDD3O2ByrzfSkEqfgz2FOR/jMbTQQ8iVq+JeEXgDc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=N87gQY0537boa77sD59OQnKJ/q45X80CxI42RoDRwWu6CUP/lzeXnr+4Pw0Jd4cB4Yicgv3frn+BJmB/oc51K+7cMnZQFi8i6mzS/n9KYiiuobRIUlvapzdO4BWG9hBWvrRxEeUYWplEtBTyPhPGRg1JDJ8bMwWk+lMc7PgppM8= 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=b3FNOgeq; arc=none smtp.client-ip=74.125.82.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="b3FNOgeq" Received: by mail-dy1-f195.google.com with SMTP id 5a478bee46e88-2af41f558f5so1976402eec.1 for ; Wed, 07 Jan 2026 13:02:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1767819736; x=1768424536; 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=e+E7Trlvt0oiegK/dgvIiDdQeWGh3NduIxLv4xKGd34=; b=b3FNOgeqEarPgzh0wct33Y1wrKOZ1miaWPU/nztZTOTqcZr7PcghaAmBgw+y1OL6FA XEXuQIigvW86SJccUB9qltHFiMjGiulFeKoXorYR2nbJuAwPYfwGPvZYhK2qD8Cd+DLN vVlW8vmwOBFEiLCnRnxBX1VlamEEBuSnOjyb6jghbnfvDiMK+ai5VBVWNc0+CrAH3IZ5 IxWgvpJvEZMpX4mz0ccZIYLeMJikXunntT+D6XxaiCr5vi+Iu933v5GjQSCXPRu/BvJz ysvclVhiaDYHMkDeFwdiPLtwGc+hYE2wivF2cguF3qHeKSkqX1c21AhFGKoNUTusqthu iv9A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1767819736; x=1768424536; 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=e+E7Trlvt0oiegK/dgvIiDdQeWGh3NduIxLv4xKGd34=; b=b8mGak+lGpKrUgRDjrd4Ra6p1BYZEoe5XJV36kad4zOjNEouCuF009ntdvYgpJ6V/l JKYi3LWCoeRMRqkie1TBVky6F+lDzVLeqyh3ymh/aoMVPB6Fn8vDBBFWQQBvP6fXWAXJ Pz21kzfy/xUJ0LgwG479A9GWpH2XZrAwCAEVh8SeeCC7/erdYrYgruaLUEx1XksjLtVH WSb/jfPSSTPwbNm109+pHjchlCOG2daWlvavREedJNemT4WRpg6bwkOC9gJW5uXq4A/+ hu6pw5DZWFv2uTW9VfmJ1DvtsqEszGZgGjbdCoXjdf3p6STHffVH7DCu/QQJ+74kkwea t9mg== X-Forwarded-Encrypted: i=1; AJvYcCVLoEyHfJ1OUVzmksOCOY113WvGQiWi+nMAlHqoDF6tDnfgTw+57HFToMukAqvbqz813o4rXtI3YyON20U=@vger.kernel.org X-Gm-Message-State: AOJu0YxKJtxZAkcA1xZ1xG0NP3BgiW11cNcI1Nf9BGFR9X7jS9EpgLFo tFOioIF1Ge5v+c8X8H31WQvYeMXRBgcN/xDAi0qarqWWIYOaBJLu5FfX X-Gm-Gg: AY/fxX40HJqLzj6d736I3Gc3K5kiKdb2g202dh0YaZoXEY1+AiyEeh0Slxy+RmjTqor J5NVKQ3iuIPn5ZQwMqajXeAfEnFx8eOMpC8SpxPOIf12vqVebd9eOiIGe7Br9vn+ATua5gp6OE9 iPJoOohjaYpTpUZ569oZH9CngP29Qbimmidqxnc3B4h7W3vi7GWFIDUlttBU0qFMLxYiwu46Hdb eD8CO4gf9JqqM21Wh51kinJkAyR/LxL5bznDEnCYNuorKG95XJ8t3WvgOZotaqsWMxyVO5H/YG+ nnCZRNaVYtw1MzOns8+sUas4t6eQ8ZhA/REl1sQ7t+4S7Px0OQCtiYpD8PtxWzWoFqPMWDx5Rq6 FMt7EaGdQe7wVaT20zjuC+qdPU60XxUzPN/+3GlOqXT4RjPnL/lpuy0/e/P0T/UO3fbxcCGCKD5 MCSxpk/OIoA0XESwsq2RFOM5J9x/JpBDUhcJVI4lB2cjhoA0A84PMr6MSbBLQf X-Google-Smtp-Source: AGHT+IGaYEwwyJ+xiqlKxx3u1rImT5in6vkJPBWncJFy16kWrM4JvVHkhraXPvmpqo2YoyQfBoyRDg== X-Received: by 2002:a05:7300:760a:b0:2af:b9af:ea7a with SMTP id 5a478bee46e88-2b17d226fb6mr3136216eec.3.1767819735571; Wed, 07 Jan 2026 13:02:15 -0800 (PST) Received: from celestia.turtle.lan (static-23-234-115-121.cust.tzulo.com. [23.234.115.121]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-2b170673b2esm7730320eec.6.2026.01.07.13.02.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Jan 2026 13:02:15 -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 v2 5/6] ceph: Assert writeback loop invariants Date: Wed, 7 Jan 2026 13:01:38 -0800 Message-ID: <20260107210139.40554-6-CFSworks@gmail.com> X-Mailer: git-send-email 2.51.2 In-Reply-To: <20260107210139.40554-1-CFSworks@gmail.com> References: <20260107210139.40554-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. 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 3becb13a09fe..f2db05b51a3b 100644 --- a/fs/ceph/addr.c +++ b/fs/ceph/addr.c @@ -1679,7 +1679,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.51.2 From nobody Sat Feb 7 13:41:30 2026 Received: from mail-dy1-f177.google.com (mail-dy1-f177.google.com [74.125.82.177]) (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 8B0A92C326F for ; Wed, 7 Jan 2026 21:02:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767819742; cv=none; b=XkQWuxNQa6XETs2RcBxKfXkAecgIS1r0Xr5E68rFEbCFr/y4UqCKT+B7ittqlHMSQH+cax5LaXEs7MKVGsPuReJawuNYuZPveHA6/biwulomEyR8BdDUKfOqeEai1x0SxS5+++SoU0ZNW4F/OnyscDF+6vHJi9KFhpar++tA8jQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767819742; c=relaxed/simple; bh=O4kJF9S8XzpGPOZTeoLxtkvaxDvktVpfrz2nWxquEuA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=PWAZrJUluuH/ipBHWgZIPRPJP+LF/fO6TBlYlw3FjG+3RlNlL6Ll81BvRK6/ngXkz3+oCKLpxUnqRvdunTwxIRHR3vXB1YJJw+3yN65c5BzIt+HUEDQDvpFzkzs7TjiZsgEKSGlNG5MJrHNXUShB4MuS8gMa2x1w52VUlTjycRg= 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=YZ228q7n; arc=none smtp.client-ip=74.125.82.177 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="YZ228q7n" Received: by mail-dy1-f177.google.com with SMTP id 5a478bee46e88-2ae38f81be1so2145892eec.0 for ; Wed, 07 Jan 2026 13:02:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1767819738; x=1768424538; 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=MJJ0g2KBjvWnpkx/2r0sdFCRqcFFwKJ2lW+TX7dGrPo=; b=YZ228q7nU+FpFr8bxyTL76iqoG32WY9xJ+K9pzlxW8VuxBZabMuBFAgj3LkdxQmyfP ocmwlOXATpEs9sGfgR2Bmi0OGNGLyuS7Vt88FWTvUe7/FdFqQktOuMLEtTGRCowjIc6F 7MV27qtOpokvJ51mWpaexNliACUHhjd5wcHOFmjh4M8SsqrjWkZagWMzm1qtbmkNYkX7 8xwn7Fy/eLxm/bz3DXeiOneMOU2mufMHPrctG+2f8KpPlkBN670L1bvMmnpiKy9amdxc +BEoKFMLIEcVVEUejpGE+pO24FNgEE1ceTuiEjrItp1l/6DPxq+FpDftivcr+U7aFn6a VivA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1767819738; x=1768424538; 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=MJJ0g2KBjvWnpkx/2r0sdFCRqcFFwKJ2lW+TX7dGrPo=; b=qkow9c8BD9ShHGlVCv4SeJuaTkiEQxbISNVlQzE8bMCIxz6bberfvcwV5Ej99hU3tz VE8k1v+YycIZ43+WYLhnU2+LVD8l9Ep8TSCpRrmiD7PFuD3i80eCI9En8xRv4PltgA8d xe+VCWjYO0pa2vZx3hSFbyegH+xGMwIj1nHFMrE/j/mMKKJs2sCQ6n+z/imuqgs9AgPa 7Y09VAAN3KUbLE1SFNVXJlBxjGmS7epWlw6yOwiP7qWBkuUQnPv/xLV4vWr2xnNgwKfl f78c0hvB1QJ/LzUN8A5Iik/czVkthfYDneI727y9tU9XokTFwntDeSI6ax/r+ao1RwzB Aq/A== X-Forwarded-Encrypted: i=1; AJvYcCV9o+s1d7J5RNnO6mRVTxHPNfAQRRJF/BKaBFn88NP1EEg8CLZ4OSGS9rK+iuEy1r/lXMGn8FtjgA/n8vY=@vger.kernel.org X-Gm-Message-State: AOJu0YxyW3KIdAlj0/Df9gjP1uA+UFeY6bq8sdPk6w/NNpK10hT+uZdn oCeYpSyE8mHnjVv7/wAwQhBvQx6hzZ5ib056b5RbPTSjL6T3eUNTRmB5 X-Gm-Gg: AY/fxX4whDtT+IuSvbfQel5+jt6s0xt+bb5tUQseI0aQUsdDr/GR2Om12j7BbVLDisW 3oqJUDoy0i7zL1yA6Mk8/mmQaJHPubwmabnpfqKdYEtTr+5kWyis9SqJbdaoK56vQ+yzz0F71Rl M38zsbxSV0QOK79vOvwxZjf0RPiHTAx8GoaCQ7iLl26Mv/NpJxw4nifKge5jY/njfaRcvU/5Zu8 NeFg/CiSuafIbtJ5Hb0fZtzmvsHRnXDuXjnbY9DWlQOaDC7AcQRidvYjDd0Vr/a3iIl6YMJzJad X+6r7/jwvkxWdaxkTyir5OVEN18rBbTo3Oj+w6DBn6S23evCazB1/+nGK/d315NNWBqAJQWm+YR hcRZrZ1vY8jkqL1ixh9QD2z23Mc0D1BdaV1sCKE23JLzACXZ0ut1os78dFWAgFvgPCF11g2MFxH uQAWWx2ib3u2fcSMHRGeRR6KOH1fiZv9yKpwqhJDZi2gfqIHyqy3FEULjU4OGm X-Google-Smtp-Source: AGHT+IFiXkVljkFfXOH3V04S1IN5M4BxUMOD54SyXL1mMom6Qzw8P2Jruw0xmxP9w0kMsCs2QmlqOA== X-Received: by 2002:a05:7300:4347:b0:2ae:582b:db80 with SMTP id 5a478bee46e88-2b17d1f023emr3128728eec.9.1767819737617; Wed, 07 Jan 2026 13:02:17 -0800 (PST) Received: from celestia.turtle.lan (static-23-234-115-121.cust.tzulo.com. [23.234.115.121]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-2b170673b2esm7730320eec.6.2026.01.07.13.02.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Jan 2026 13:02:17 -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 , stable@vger.kernel.org Subject: [PATCH v2 6/6] ceph: Fix write storm on fscrypted files Date: Wed, 7 Jan 2026 13:01:39 -0800 Message-ID: <20260107210139.40554-7-CFSworks@gmail.com> X-Mailer: git-send-email 2.51.2 In-Reply-To: <20260107210139.40554-1-CFSworks@gmail.com> References: <20260107210139.40554-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" CephFS stores file data across multiple RADOS objects. An object is the atomic unit of storage, so the writeback code must clean only folios that belong to the same object with each OSD request. CephFS also supports RAID0-style striping of file contents: if enabled, each object stores multiple unbroken "stripe units" covering different portions of the file; if disabled, a "stripe unit" is simply the whole object. The stripe unit is (usually) reported as the inode's block size. Though the writeback logic could, in principle, lock all dirty folios belonging to the same object, its current design is to lock only a single stripe unit at a time. Ever since this code was first written, it has determined this size by checking the inode's block size. However, the relatively-new fscrypt support needed to reduce the block size for encrypted inodes to the crypto block size (see 'fixes' commit), which causes an unnecessarily high number of write operations (~1024x as many, with 4MiB objects) and correspondingly degraded performance. Fix this (and clarify intent) by using i_layout.stripe_unit directly in ceph_define_write_size() so that encrypted inodes are written back with the same number of operations as if they were unencrypted. Fixes: 94af0470924c ("ceph: add some fscrypt guardrails") Cc: stable@vger.kernel.org Signed-off-by: Sam Edwards --- fs/ceph/addr.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/fs/ceph/addr.c b/fs/ceph/addr.c index f2db05b51a3b..b97a6120d4b9 100644 --- a/fs/ceph/addr.c +++ b/fs/ceph/addr.c @@ -1000,7 +1000,8 @@ unsigned int ceph_define_write_size(struct address_sp= ace *mapping) { struct inode *inode =3D mapping->host; struct ceph_fs_client *fsc =3D ceph_inode_to_fs_client(inode); - unsigned int wsize =3D i_blocksize(inode); + struct ceph_inode_info *ci =3D ceph_inode(inode); + unsigned int wsize =3D ci->i_layout.stripe_unit; =20 if (fsc->mount_options->wsize < wsize) wsize =3D fsc->mount_options->wsize; --=20 2.51.2